21,892
社区成员
发帖
与我相关
我的任务
分享
<?php
$arr = array(
array('id'=>3,'username'=>'alex','parentname'=>'john','proname'=>'tttt','num'=> 1 , 'userid' =>6 ,'parentid'=>8 ,'cpid'=> 0 ,'mobile'=> 15533336666 ,'parentmobile' => 156477765465),
array('id'=>3,'username'=>'alex','parentname'=>'john','proname'=>'tttt','num'=> 1 , 'userid' =>6 ,'parentid'=>8 ,'cpid'=> 0 ,'mobile'=> 15533336666 ,'parentmobile' => 156477765465),
array('id'=>3,'username'=>'alex','parentname'=>'john','proname'=>'tttt','num'=> 1 , 'userid' =>6 ,'parentid'=>8 ,'cpid'=> 0 ,'mobile'=> 15533336666 ,'parentmobile' => 156477765465),
);
$result = array();
$fields = array('id','username','mobile','parentname','parentmobile','proname','num','userid','parentid','cpid');
foreach($arr as $k=>$v){
$tmp = array();
foreach($fields as $f){
$tmp[$f] = $v[$f];
}
$result[] = $tmp;
}
print_r($result);
$a = Array ( 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');
foreach($a as $i=>$v) {
extract($v);
$a[$i] = compact($k);
}
print_r($a);
Array
(
[0] => Array
(
[id] => 3
[username] => alex
[mobile] => 15533336666
[parentname] => john
[parentmobile] => 156477765465
[proname] => tttt
[num] => 1
[userid] => 6
[parentid] => 8
[cpid] => 0
)
)