unset not deleting key in multidimensional array

51 Views Asked by At

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.

1

There are 1 best solutions below

0
Carlos Alves Jorge On BEST ANSWER

Easy and fast to understand way

$t=0;
foreach ($arr as $val)
{
      unset($arr[$temp]['deliveryLocation']);
      $t++;
}