0

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.

Mohsin
  • 179
  • 4
  • 13

1 Answers1

0

Easy and fast to understand way

$t=0;
foreach ($arr as $val)
{
      unset($arr[$temp]['deliveryLocation']);
      $t++;
}
Carlos Alves Jorge
  • 1,919
  • 1
  • 13
  • 29