Heim >Backend-Entwicklung >PHP-Tutorial >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 "
";
//第一种方法:
foreach ($result as $key =>$v){
$new_arr[]=$v[0];
}
echo '
';<br>print_r($new_arr);<br>//第二种方法<br>//初始化$arr2 <br>$arr2=array(); <br> <br>//循环遍历三维数组$arr3 <br>foreach($result as $value){ <br> foreach($value as $v){ <br> $arr2[]=$v; <br> } <br>}<br>//销毁$arr3 <br>unset($result,$value,$v);<br>echo "<br>";<br>echo "第二种方法:";<br>echo '<pre class="brush:php;toolbar:false">';<br>print_r($arr2);<br>?<br>?> <p> 以上就介绍了 php三维数组转二维数组,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。</p> <p> </p>