Home > Backend Development > PHP Tutorial > PHP three-dimensional array to two-dimensional array

PHP three-dimensional array to two-dimensional array

WBOY
Release: 2016-07-28 08:28:27
Original
1593 people have browsed it

$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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template