<code>$arr = [ ['id'=>1,'name'=>'php'], ['id'=>2,'name'=>'js'], ['id'=>3,'name'=>'python'], ['id'=>4,'name'=>'java'] ]; //删除id为4的一维数组,除了unset还有其他方法吗 foreach($arr as $key=>$value){ if($value['id'] == 4) unset($arr[$key]); } echo '<pre class="brush:php;toolbar:false">';print_r($arr);
<code>$arr = [ ['id'=>1,'name'=>'php'], ['id'=>2,'name'=>'js'], ['id'=>3,'name'=>'python'], ['id'=>4,'name'=>'java'] ]; //删除id为4的一维数组,除了unset还有其他方法吗 foreach($arr as $key=>$value){ if($value['id'] == 4) unset($arr[$key]); } echo '<pre class="brush:php;toolbar:false">';print_r($arr);
<code>print_r(array_filter($arr, function($var) {return $var['id']!=4;})); </code>
本质还是循环的