3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a1 = [ 'from' => 'Paris', 'to' => 'Marseille', ]; $a2 = [ 'from' => 'Marseille', 'to' => 'Valencia', ]; $a3 = [ 'from' => 'Valencia', 'to' => 'Algiers', ]; $a4 = [ 'from' => 'Algiers', 'to' => 'Abu Dhabi', ]; $route = array($a4, $a3, $a1, $a2); $from = array_column($route, 'from'); $to = array_column($route, 'to'); $start = array_diff($from, $to); $sortedRoute = [$route[key($start)]]; $start = $route[key($start)]['to']; while (true) { $key = array_search($start, $from); if ($key === false) break; $sortedRoute[] = $route[$key]; $start = $route[$key]['to']; } var_dump($sortedRoute);
Output for 5.5.0 - 5.5.35, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 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.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.14, 8.4.16 - 8.4.17, 8.5.0 - 8.5.2
array(4) { [0]=> array(2) { ["from"]=> string(5) "Paris" ["to"]=> string(9) "Marseille" } [1]=> array(2) { ["from"]=> string(9) "Marseille" ["to"]=> string(8) "Valencia" } [2]=> array(2) { ["from"]=> string(8) "Valencia" ["to"]=> string(7) "Algiers" } [3]=> array(2) { ["from"]=> string(7) "Algiers" ["to"]=> string(9) "Abu Dhabi" } }
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
212.45 ms | 407 KiB | 5 Q