0

我有多维数组,想删除它存在的交付位置

   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;

问题是它按原样返回上面的数组,而没有从中删除任何键。

4

1 回答 1

0

简单快速的理解方式

$t=0;
foreach ($arr as $val)
{
      unset($arr[$temp]['deliveryLocation']);
      $t++;
}
于 2019-05-09T07:40:57.397 回答