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);

?

?>

    原文作者:sunlong19870812
    原文地址: https://blog.csdn.net/sunlong19870812/article/details/78725266
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞