在多维数组中未设置

时间:2019-05-14 19:16:41

标签: php multidimensional-array foreach

这是我的数组:

 array(
  [0] => Array (    
      [field_type] => title 
       [_id] => 4d143e6 ) 
  [1] => Array ( 
      [field_type] => title 
      [_id] => 89ff3a3 ) 
   );

如何从此数组中删除_id键。请帮助

1 个答案:

答案 0 :(得分:3)

<?php

$arr = [
   [
      'field_type' => 'Title',
      '_id' => 1
   ],
   [
      'field_type' => 'Title',
      '_id' => 2
   ]
];

// Pass by reference to allow array mutation
foreach($arr as &$a)
{
   unset($a['_id']);
}

print_r($arr);