廢話不多說了,直接給大家貼代碼了,具體代碼如下所示:
<?php $arr = [ [,,,,], [,,,,] ]; $arr = [ 'list' => [ [,,,], [,,,], [,,,], ] ]; $arr = [ 'list' => [ [,,,], [,,,], [,,,] ] ]; $res = array_map(function($arr){ return array_filter($arr, function($v) { return $v !== ; }); }, $arr); $res = array_map(function($val) { return array_filter($val, function($v) { return !in_array(, $v); }); }, $arr); $res = []; array_walk($arr, function($val, $key) use(&$res) { $res[$key] = array_filter($val, function($v) { return !in_array(, $v); }); }); var_dump($res); var_dump($res);
下面一段代碼給大家介紹php三維數組變二維數組
<?php $result = Array(0 => Array(0 => Array(bid => 41,brealname => 'we教官',cid => 41,crealname => 'we教官')), 1 => Array(0 => Array(bid => 6,brealname => '虎子',cid => 19,crealname => '張魚')) ); //原數組 print_r($result); echo "<br />"; //第一種方法: foreach ($result as $key =>$v){ $new_arr[]=$v[0]; } echo '<pre>'; print_r($new_arr); //第二種方法 //初始化$arr2 $arr2=array(); //循環遍歷三維數組$arr3 foreach($result as $value){ foreach($value as $v){ $arr2[]=$v; } } //銷毀$arr3 unset($result,$value,$v); echo "<br /s>"; echo "第二種方法:"; echo '<pre>'; print_r($arr2); ?>
關於PHP 二維數組和三維數組的過濾小編就給大家介紹這麼多,希望對大家有所幫助!