Home > Backend Development > PHP Tutorial > php一维数组重新排序

php一维数组重新排序

WBOY
Release: 2016-06-23 13:04:29
Original
1733 people have browsed it

 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);
Copy after login
array (  'id' => 3,  'username' => 'alex ',  'mobile' => 15533336666,  'parentname' => 'john',  'parentmobile' => 156477765465,  'proname' => 'tttt',  'num' => 1,  'userid' => 6,  'parentid' => 8,  'cpid' => 0,)
Copy after login

多谢了,能否不用extract和compact ,只用foreach能实现吗?谢谢了

如果没有样本,就不可能完成
如果有样本,还拘泥于形式,有什么意义吗?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template