3v4l.org

run code in 500+ PHP versions simultaneously
<?php function findWayPoints(array $lookup, $start, $end, array $path = []): ?array { if (isset($lookup[$start][$end])) { return $path; // full path found; no need to further recurse } foreach ($lookup[$start] ?? [] as $conn => $irrelevant) { $result = findWayPoints( array_diff_key($lookup, [$start => null]), // eliminate circular/infinite recursion $conn, // change starting node in next call $end, array_merge($path, [$conn]) // append current match to path ); if ($result !== null) { return $result; } } return null; // dead end; kill path } function buildLookup($nodes) { $lookup = []; foreach ($nodes as $k => [$connections]) { foreach (explode(' ', $connections) as $conn) { $lookup[$k][$conn] = true; $lookup[$conn][$k] = true; } } return $lookup; } $nodes = [ 'f' => ['d g'], 'b' => ['a d'], 'g' => ['i'], 'd' => ['c e'], 'i' => ['h'] ]; $lookup = buildLookup($nodes); echo json_encode(findWayPoints($lookup, 'h', 'f')); echo "\n---\n"; echo json_encode(findWayPoints($lookup, 'f', 'h')); echo "\n---\n"; echo json_encode(findWayPoints($lookup, 'a', 'c')); echo "\n---\n"; echo json_encode(findWayPoints($lookup, 'a', 'b')); echo "\n---\n"; echo json_encode(findWayPoints($lookup, 'a', 'h')); echo "\n---\n"; echo json_encode(findWayPoints($lookup, 'i', 'j'));

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.5.30.0100.00821.33
8.5.20.0140.01220.27
8.5.10.0120.00618.51
8.5.00.0130.00820.02
8.4.180.0130.00919.74
8.4.170.0110.01023.82
8.4.160.0130.00923.84
8.4.150.0070.00616.87
8.4.140.0100.01117.55
8.4.130.0030.00518.73
8.4.120.0150.00323.92
8.4.110.0120.01018.76
8.4.100.0120.00818.83
8.4.90.0110.00920.70
8.4.80.0040.00418.75
8.4.70.0080.01317.96
8.4.60.0100.01018.90
8.4.50.0130.00718.68
8.4.40.0060.01318.84
8.4.30.0080.01118.58
8.4.20.0160.00319.47
8.4.10.0060.00319.39
8.3.300.0100.01022.60
8.3.290.0090.01120.92
8.3.280.0120.00818.47
8.3.270.0100.00816.69
8.3.260.0110.00516.68
8.3.250.0090.01019.03
8.3.240.0100.00817.27
8.3.230.0170.00216.73
8.3.220.0100.00619.16
8.3.210.0130.00616.72
8.3.200.0050.00316.50
8.3.190.0120.00818.79
8.3.180.0070.01117.42
8.3.170.0130.00718.84
8.3.160.0070.01116.77
8.3.150.0120.00617.20
8.3.140.0040.01116.81
8.3.130.0030.00616.71
8.3.120.0060.00918.78
8.3.110.0050.00520.94
8.3.100.0060.00324.06
8.3.90.0080.00426.77
8.3.80.0080.00316.61
8.3.70.0060.00916.63
8.3.60.0090.00618.24
8.3.50.0040.01216.68
8.3.40.0380.01017.63
8.3.30.0310.01717.49
8.3.20.0360.00717.50
8.3.10.0350.00917.63
8.3.00.0460.00417.50
8.2.300.0120.00718.77
8.2.290.0120.00620.75
8.2.280.0140.00618.47
8.2.270.0090.00917.37
8.2.260.0120.00316.58
8.2.250.0080.00018.56
8.2.240.0000.00916.41
8.2.230.0000.01022.58
8.2.220.0030.00637.54
8.2.210.0050.00326.77
8.2.200.0100.00016.75
8.2.190.0120.00618.29
8.2.180.0100.01018.17
8.2.170.0500.00317.50
8.2.160.0390.01117.73
8.2.150.0320.01617.60
8.2.140.0380.00417.36
8.2.130.0270.02017.38
8.2.120.0480.01017.47
8.2.110.0270.01217.38
8.2.100.0230.01717.50
8.2.90.0290.00617.63
8.2.80.0370.00317.63
8.2.70.0340.00617.38
8.2.60.0410.01117.50
8.2.50.0450.00417.50
8.2.40.0300.01017.63
8.2.30.0320.01117.50
8.2.20.0160.01017.63
8.2.10.0380.00817.63
8.2.00.0400.00717.38
8.1.340.0120.00721.47
8.1.330.0100.00922.17
8.1.320.0120.00617.88
8.1.310.0040.01116.83
8.1.300.0060.00316.36
8.1.290.0090.00018.88
8.1.280.0090.00625.92
8.1.270.0370.01317.38
8.1.260.0460.00417.23
8.1.250.0440.00617.23
8.1.240.0360.01217.25
8.1.230.0370.00617.23
8.1.220.0410.00317.35
8.1.210.0280.01117.36
8.1.200.0620.01217.23
8.1.190.0470.00317.13
8.1.180.0410.00717.00
8.1.170.0280.01617.34
8.1.160.0320.00917.21
8.1.150.0290.01017.23
8.1.140.0340.01317.10
8.1.130.0430.00617.21
8.1.120.0330.00716.88
8.1.110.0290.01117.13
8.1.100.0360.01117.34
8.1.90.0350.00417.22
8.1.80.0300.00417.22
8.1.70.0460.00717.25
8.1.60.0430.01017.50
8.1.50.0320.00917.25
8.1.40.0340.01317.38
8.1.30.0270.00817.50
8.1.20.0280.01817.50
8.1.10.0270.01217.00
8.1.00.0310.00717.13

preferences:
44.11 ms | 981 KiB | 5 Q