I have an array like this:
$arr = [
['id' => 12, 'name' => 'Martin', 'cellphone' => '0019949437'],
['id' => 15, 'name' => 'Alex', 'cellphone' => "00183847394"]
];
I need to remove the cellphone item from array above. I wrote an code to do that like this:
$res = array_filter($arr, function($arr){ unset($arr['cellphone']); return $arr; });
But still that item exists and the $res is the same as $arr. What's wrong? What unset doesn't happen?
array_filterfor this to begin with, this would be much more a use case forarray_walk.unsetwon't work since$arrisn't a ref to the real array. Use a loop.array_filterwould be to completely remove items from$arr- that is not what you want to do to begin with, you want to modify the items.