首页 > 代码库 > 相信有时候你会用到。数组$arr1转换成另一个数组$arr2

相信有时候你会用到。数组$arr1转换成另一个数组$arr2

$arr1 = array (

‘0‘ => array (‘fid‘ => 1, ‘tid‘ => 1, ‘name‘ =>‘Name1‘ ),

‘1‘ => array (‘fid‘ => 1, ‘tid‘ => 2 , ‘name‘ =>‘Name2‘ ),

‘2‘ => array (‘fid‘ => 1, ‘tid‘ => 5 , ‘name‘ =>‘Name3‘ ),

‘3‘ => array (‘fid‘ => 1, ‘tid‘ => 7 , ‘name‘ =>‘Name4‘ ),

‘4‘ => array (‘fid‘ => 3, ‘tid‘ => 9, ‘name‘ =>‘Name5‘ )

 );


    foreach($arr1 as $k => $v){

        $temp[$v[‘fid‘]][] = array(

            ‘tid‘ => $v[‘tid‘],

            ‘name‘ => $v[‘name‘],

        );

    }

    foreach($temp as $v){

        $arr2[] = $v;

    }

    var_dump($arr2);die;


相信有时候你会用到。数组$arr1转换成另一个数组$arr2