3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array_A = []; $array_B = []; $array_A[0]['name'] = "Robson"; $array_A[0]['value'] = "ROB"; $array_A[1]['name'] = "Morticia"; $array_A[1]['value'] = "MORT"; $array_A[2]['name'] = "John"; $array_A[2]['value'] = "JO"; $array_A[3]['name'] = "Zeke"; $array_A[3]['value'] = "ZE"; $array_B[0] = "Morticia"; $array_B[1] = "Robson"; $array_B[2] = "Zeke"; $array_B[3] = "John"; usort($array_A, function($a, $b) use ($array_B) { return array_search($a['name'], $array_B) > array_search($b['name'], $array_B); }); print_r($array_A);
Output for 8.2.0 - 8.2.19, 8.3.0 - 8.3.4, 8.3.6 - 8.3.7
Deprecated: usort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in /in/MJ4TG on line 20 Array ( [0] => Array ( [name] => Morticia [value] => MORT ) [1] => Array ( [name] => Robson [value] => ROB ) [2] => Array ( [name] => Zeke [value] => ZE ) [3] => Array ( [name] => John [value] => JO ) )
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Deprecated: usort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in /in/MJ4TG on line 20 Array ( [0] => Array ( [name] => Morticia [value] => MORT ) [1] => Array ( [name] => Robson [value] => ROB ) [2] => Array ( [name] => Zeke [value] => ZE ) [3] => Array ( [name] => John [value] => JO ) )
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
Deprecated: usort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in /in/MJ4TG on line 22 Array ( [0] => Array ( [name] => Morticia [value] => MORT ) [1] => Array ( [name] => Robson [value] => ROB ) [2] => Array ( [name] => Zeke [value] => ZE ) [3] => Array ( [name] => John [value] => JO ) )
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Array ( [0] => Array ( [name] => Morticia [value] => MORT ) [1] => Array ( [name] => Robson [value] => ROB ) [2] => Array ( [name] => Zeke [value] => ZE ) [3] => Array ( [name] => John [value] => JO ) )

preferences:
133.77 ms | 403 KiB | 183 Q