Reputation: 179
I have multidimensional array and wants to remove delivery location where ever it exists
Array
(
[0] => Array
(
[amountReceived] => 1
[deliveryLocation] => germany
)
[1] => Array
(
[amountReceived] => 2
[deliveryLocation] => bulgaria
)
)
PHP
foreach ($arr as $val)
{
foreach($val as $k => $v)
{
if($k == 'deliveryLocation')
{
unset($arr[$k]);
}
}
}
return $arr;
problem is it's returning above array as it is without removing any key from it.
Upvotes: 0
Views: 49
Reputation: 1985
Easy and fast to understand way
$t=0;
foreach ($arr as $val)
{
unset($arr[$temp]['deliveryLocation']);
$t++;
}
Upvotes: 0