网站建设资讯

NEWS

网站建设资讯

php数组三维转二维

php数组三维转二维

创新互联是一家专注网站建设、网络营销策划、微信小程序、电子商务建设、网络推广、移动互联开发、研究、服务为一体的技术型公司。公司成立十载以来,已经为数千家建筑动画各业的企业公司提供互联网服务。现在,服务的数千家客户与我们一路同行,见证我们的成长;未来,我们一起分享成功的喜悦。

当心,上代码:

// 测试用的数组
$my_array = array (
    '0'=>array(
            '0'=>array('no'=>1212,'ret'=>'09'),
            '1'=>array('no'=>1213,'ret'=>'09'),
            '2'=>array('no'=>1214,'ret'=>'09'),
        ),
    '1'=>array(
            '0'=>array('no'=>1213,'ret'=>'10'),
            '1'=>array('no'=>1214,'ret'=>'10'),
            '2'=>array('no'=>1215,'ret'=>'10'),
        ),

);

$newhello=array();

$k = 0;
foreach ($my_array as $key => $val) {
    foreach ($val as $key2 => $val2) {
        $newhello[$k]['no'] = $val2['no'];
        $newhello[$k]['ret'] = $val2['ret'];
        $k++;
    }
}

echo '
';
print_r($my_array);
print_r($newhello);
exit();

打印运行结果:

Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [no] => 1212
                    [ret] => 09
                )

            [1] => Array
                (
                    [no] => 1213
                    [ret] => 09
                )

            [2] => Array
                (
                    [no] => 1214
                    [ret] => 09
                )

        )

    [1] => Array
        (
            [0] => Array
                (
                    [no] => 1213
                    [ret] => 10
                )

            [1] => Array
                (
                    [no] => 1214
                    [ret] => 10
                )

            [2] => Array
                (
                    [no] => 1215
                    [ret] => 10
                )

        )

)
Array
(
    [0] => Array
        (
            [no] => 1212
            [ret] => 09
        )

    [1] => Array
        (
            [no] => 1213
            [ret] => 09
        )

    [2] => Array
        (
            [no] => 1214
            [ret] => 09
        )

    [3] => Array
        (
            [no] => 1213
            [ret] => 10
        )

    [4] => Array
        (
            [no] => 1214
            [ret] => 10
        )

    [5] => Array
        (
            [no] => 1215
            [ret] => 10
        )

)

网站栏目:php数组三维转二维
文章来源:http://cdweb.net/article/gepijc.html