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

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

40,026 questions

51,982 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
...