学无止境,天涯煮梦!

PHP之降维打击

2018-09-19 22:44:15 | 煮梦 | 常规

以下是一个三维数组

$result = array(
    array(
        array(
            'bid' => 1,
            'brealname' => 'lll',
            'cid' => 2,
            'crealname' => 'aaa'
        )
    ),
    array(
        array(
            'bid' => 3,
            'brealname' => 'ccc',
            'cid' => 4,
            'crealname' => 'ddd'
        )
    )
);

降维打击开始

foreach($result as $value){
    $arr[] = $value[0];   
}

print_r($arr); -> 会把最外层的array给去掉,于是变成了二维的,如下

Array
(
    [0] => Array
        (
            [bid] => 1
            [brealname] => lll
            [cid] => 2
            [crealname] => aaa
        )

)
Array
(
    [0] => Array
        (
            [bid] => 1
            [brealname] => ccc
            [cid] => 2
            [crealname] => ddd
        )

)
上一篇 下一篇