3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = ['val1', 'val2', 200, 179, 230, 234, 242]; $order = [230, 234, 242, 179, 100]; $keyedOrder = array_flip($order); // for efficiency usort($array, fn($a, $b) => [$keyedOrder[$a] ?? -1, $a] <=> [$keyedOrder[$b] ?? -1, $b]); var_export($array);
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
array ( 0 => 200, 1 => 'val1', 2 => 'val2', 3 => 230, 4 => 234, 5 => 242, 6 => 179, )
Output for 7.4.0 - 7.4.33
array ( 0 => 'val1', 1 => 'val2', 2 => 200, 3 => 230, 4 => 234, 5 => 242, 6 => 179, )
Output for 7.3.0 - 7.3.33
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ')' in /in/qAmLV on line 7
Process exited with code 255.
Output for 7.2.0 - 7.2.33
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ',' or ')' in /in/qAmLV on line 7
Process exited with code 255.

preferences:
48.59 ms | 409 KiB | 5 Q