php三維陣列變二維陣列
阿新 • • 發佈:2019-01-05
<?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); ?>