3v4l.org

run code in 300+ PHP versions simultaneously
<?php $sortMe = ['A','B','C','D']; $sortMeToo = ['1','2','3','4']; arsort($sortMe); $sortedKeys = array_keys($sortMe); $newSortMeToo = []; foreach ($sortedKeys as $sortedKey) { $newSortMeToo[] = $sortMeToo[$sortedKey]; } $sortMeToo = $newSortMeToo; var_dump($sortMe); var_dump($sortMeToo);
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
array(4) { [3]=> string(1) "D" [2]=> string(1) "C" [1]=> string(1) "B" [0]=> string(1) "A" } array(4) { [0]=> string(1) "4" [1]=> string(1) "3" [2]=> string(1) "2" [3]=> string(1) "1" }

preferences:
110.81 ms | 408 KiB | 5 Q