Rumah >pembangunan bahagian belakang >tutorial php >php一维数组重新排序
Array ('id' => 3, 'username' => 'alex ','parentname'=> 'john'
,'proname' => 'tttt' 'num'=> 1 , 'userid' =>6 ,'parentid'=>8 ,
'cpid'=> 0 ,'mobile'=> 15533336666 ,'parentmobile' => 156477765465) ;
把最后两个分别放在第2个和第4个位置 ,怎么重新排序?
Array ('id' => 3, 'username' => 'alex ','mobile'=> 15533336666
,'parentname'=> 'john' ,'parentmobile' => 156477765465 ,'proname' => 'tttt' 'num'=> 1 ,
'userid' =>6 ,'parentid'=>8 ,'cpid'=> 0 );
$a = Array( 'id' => 3, 'username' => 'alex ', 'parentname'=> 'john', 'proname' => 'tttt', 'num'=> 1 , 'userid' =>6 , 'parentid'=>8 , 'cpid'=> 0 , 'mobile'=> 15533336666 , 'parentmobile' => 156477765465);$k = array ( 'id', 'username', 'mobile', 'parentname', 'parentmobile', 'proname', 'num', 'userid', 'parentid', 'cpid', 'mobile',);extract($a);$b = compact($k);var_export($b);
array ( 'id' => 3, 'username' => 'alex ', 'mobile' => 15533336666, 'parentname' => 'john', 'parentmobile' => 156477765465, 'proname' => 'tttt', 'num' => 1, 'userid' => 6, 'parentid' => 8, 'cpid' => 0,)
多谢了,能否不用extract和compact ,只用foreach能实现吗?谢谢了
如果没有样本,就不可能完成
如果有样本,还拘泥于形式,有什么意义吗?