Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,051 questions

40,769 answers

573 users

How to sort several (multiple) arrays at once in PHP

2 Answers

0 votes
$arr1 = array( 1,  3,   2,  5, 4);
$arr2 = array(30, 30, 100, 20, 1);
array_multisort($arr1, $arr2);

print_r($arr1);
echo "<br />";
print_r($arr2);

// $arr2 corresponding to the identical entries in $arr1

/*
run:
 
Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 )
Array ( [0] => 30 [1] => 100 [2] => 30 [3] => 1 [4] => 20 ) 
 
*/

 





answered Jul 28, 2015 by avibootz
0 votes
$arr1 = array(30, 30, 100, 20, 1);
$arr2 = array( 1,  3,   2,  5, 4);
array_multisort($arr1, $arr2);

print_r($arr1);
echo "<br />";
print_r($arr2);

// $arr2 corresponding to the identical entries in $arr1

/*
run:
 
Array ( [0] => 1 [1] => 20 [2] => 30 [3] => 30 [4] => 100 )
Array ( [0] => 4 [1] => 5 [2] => 1 [3] => 3 [4] => 2 ) 
 
*/

 





answered Jul 28, 2015 by avibootz
...