Home >Backend Development >PHP Tutorial >PHP three-dimensional array to two-dimensional array
$result = Array(0 => Array(0 => Array(bid => 41,brealname => 'we instructor',cid => 41,crealname => 'we instructor ')),
1 => Array(0 => Array(bid => 6,brealname => 'Huzi',cid => 19,crealname => 'Zhangyu'))
);
//Original array
print_r($result);
echo "
";
//First method:
foreach ($result as $key =>$v){
$ new_arr[]=$v[0];
}
echo '
';
print_r($new_arr);
//Second method
//Initialize $arr2
$arr2=array();
//Loop through the three-dimensional array $arr3
foreach($result as $value){
foreach($value as $v){
$arr2[]=$v;
}
}
//Destroy $arr3
unset ($result,$value,$v);
echo "
";
echo "Second method:";
echo '';
print_r($arr2);
?
?>The above has introduced the conversion of three-dimensional arrays into two-dimensional arrays in PHP, including all aspects. I hope it will be helpful to friends who are interested in PHP tutorials.