Please help me to re-sort the php 2D Array ('id' => 3, 'username' => 'Alex ', 'parentname' => 'John'
, 'Proname' => 'tttttt' 'num' => 1, 'userid' => 6, 'parentid' => 8,
'Cpid' => 0, 'mobile' => 15533336666, 'parentmobile' => 156477765465 ));
How can I re-sort the last two places in the 2nd and 4th locations?
Array ('id' => 3, 'username' => 'Alex ', 'mobile' => 15533336666
, 'Parentname' => 'John', 'parentmobile '=> 156477765465, 'proname' => 'tttttt' 'num' => 1,
'Userid' => 6, 'parentid' => 8, 'cpid' => 0 );
Reply to discussion (solution)
What sort do you consider?
Isn't it just about tuning the location? Why?
Finally, I want to use excel for output. if the sorting is not like this, the format will be messy.
Is there a way to sort 100 records from the database?
What sort do you consider?
Isn't it just about tuning the location? Why?
What sort do you consider?
Isn't it just about tuning the location? Why?
Is there a way to adjust the location? Thank you.
Is there a way to sort 100 records from the database?
Slave Database? Can you directly change the order when querying?
Is there a way to sort 100 records from the database?
Slave Database? Can you directly change the order when querying?
The last two fields are the result of indirect query from another table and then appended with an array, which leads to the current location problem.
1. do not simply select *
Instead, select id, username, mobile... is listed one by one, and the order you requested is not there.
2. php code can also be used.
$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 ))
Your key => value
How to arrange does not affect the use.
But you can write it like this.
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);
Thank you for your advice.
If the problem is solved, please close the post.