3v4l.org

run code in 300+ PHP versions simultaneously
<?php $resultset = [ // query just once, collect the full tree ["ID" => 1, "Name" => "News", "Father" => 0], ["ID" => 2, "Name" => "Articles", "Father" => 0], ["ID" => 3, "Name" => "Politics", "Father" => 1], ["ID" => 4, "Name" => "Politics", "Father" => 2], ["ID" => 5, "Name" => "World", "Father" => 3], ["ID" => 6, "Name" => "World", "Father" => 4] ]; $path = "/News/Politics/World"; // $path = "/Articles/The Funnies/Garfield"; // a test case that fails // News: parent = 0, id = 1 // \ // Politics: parent = 1, id = 3 // > the intended logic // World: parent = 3, id = 5 // / $cfg['categories_separator'] = "/"; $breadcrumbs = explode($cfg['categories_separator'], trim($path, "/")); // var_export($breadcrumbs); // see what is generated $parent = 0; // default value foreach ($breadcrumbs as $crumb) { $id = false; // set invalid value for success check foreach ($resultset as $row) { if ($row["Name"] == $crumb && $parent == $row["Father"]) { // qualifying match $id = $parent = $row["ID"]; // dual declaration break; // break inner loop, progress to next $crumb } } if (!$id) { // inner loop failed to find qualifying match echo "Uh-oh, Broken Breadcrumb Path -- $crumb not found in $path\n"; break; // break outer loop, path is invalid } // echo "ID = $id for $crumb\n"; // uncomment to see progress } echo "ID = $id for $crumb\n"; // echo the result

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.3.70.0130.01018.71
8.3.60.0040.01118.18
8.3.50.0150.00018.41
8.3.40.0130.00318.71
8.3.30.0110.00418.84
8.3.20.0040.00418.77
8.3.10.0050.00221.89
8.3.00.0080.00021.82
8.2.190.0110.00416.80
8.2.180.0070.00718.18
8.2.170.0100.00722.96
8.2.160.0100.00320.39
8.2.150.0070.00025.66
8.2.140.0050.00224.66
8.2.130.0050.00326.16
8.2.120.0000.00720.80
8.2.110.0060.00321.04
8.2.100.0070.00417.84
8.2.90.0050.00220.59
8.2.80.0060.00320.50
8.2.70.0080.00017.63
8.2.60.0040.00417.50
8.2.50.0040.00418.03
8.2.40.0080.00019.78
8.2.30.0060.00318.16
8.2.20.0000.00818.10
8.2.10.0060.00318.04
8.2.00.0000.00818.13
8.1.280.0150.00625.92
8.1.270.0030.00520.31
8.1.260.0060.00926.35
8.1.250.0040.00428.09
8.1.240.0060.00322.05
8.1.230.0040.00720.91
8.1.220.0060.00317.74
8.1.210.0040.00418.88
8.1.200.0080.00017.48
8.1.190.0040.00417.25
8.1.180.0130.00318.10
8.1.170.0040.00417.62
8.1.160.0040.00418.93
8.1.150.0040.00418.55
8.1.140.0060.00317.49
8.1.130.0030.00322.00
8.1.120.0000.00717.50
8.1.110.0000.00717.43
8.1.100.0110.00017.44
8.1.90.0050.00217.45
8.1.80.0000.01117.33
8.1.70.0040.00417.34
8.1.60.0050.00317.63
8.1.50.0040.00417.41
8.1.40.0080.00017.55
8.1.30.0040.00417.54
8.1.20.0040.00417.64
8.1.10.0000.00717.53
8.1.00.0000.00717.33
8.0.300.0040.00420.23
8.0.290.0000.00716.63
8.0.280.0000.00818.44
8.0.270.0000.00817.25
8.0.260.0060.00018.42
8.0.250.0030.00516.95
8.0.240.0030.00616.84
8.0.230.0000.00716.94
8.0.220.0030.00716.91
8.0.210.0040.00416.92
8.0.200.0030.00316.96
8.0.190.0000.00716.96
8.0.180.0040.00416.93
8.0.170.0090.00016.79
8.0.160.0000.00716.96
8.0.150.0000.00816.77
8.0.140.0030.00316.84
8.0.130.0050.00013.27
8.0.120.0040.00416.86
8.0.110.0050.00316.88
8.0.100.0040.00416.68
8.0.90.0050.00216.89
8.0.80.0090.00916.86
8.0.70.0040.00416.75
8.0.60.0050.00216.74
8.0.50.0040.00416.93
8.0.30.0130.00717.14
8.0.20.0080.01117.40
8.0.10.0040.00417.07
8.0.00.0050.01416.94
7.4.330.0050.00015.55
7.4.320.0000.00716.51
7.4.300.0040.00416.58
7.4.290.0070.00016.58
7.4.280.0000.00816.39
7.4.270.0000.00716.60
7.4.260.0030.00316.49
7.4.250.0040.00416.46
7.4.240.0080.00016.52
7.4.230.0000.00716.61
7.4.220.0000.00816.58
7.4.210.0120.00616.50
7.4.200.0000.00716.60
7.4.160.0100.00916.55
7.4.140.0070.01117.86
7.4.130.0130.00616.54
7.4.120.0100.00816.48
7.4.110.0090.00916.54
7.4.100.0120.00616.36
7.4.90.0100.01716.55
7.4.80.0120.00919.39
7.4.70.0100.01016.53
7.4.60.0100.00716.54
7.4.50.0030.01016.43
7.4.40.0100.00716.59
7.4.00.0070.01014.84
7.3.330.0000.00513.15
7.3.320.0030.00313.31
7.3.310.0070.00016.37
7.3.300.0070.00016.34
7.3.290.0060.00016.33
7.3.280.0110.00416.36
7.3.260.0130.00716.39
7.3.240.0080.01116.37
7.3.230.0100.00716.56
7.3.210.0110.00616.35
7.3.200.0090.00616.28
7.3.190.0100.01016.48
7.3.180.0030.01316.29
7.3.170.0080.00816.52
7.3.160.0120.00416.42
7.2.330.0120.00916.86
7.2.320.0060.01016.76
7.2.310.0070.01116.68
7.2.300.0130.00316.71
7.2.290.0090.00916.80
7.2.100.0820.00714.18
7.2.90.1110.01014.67
7.2.80.0600.01014.55
7.2.70.0980.00314.80
7.2.60.0640.01014.69
7.2.50.0740.00315.14
7.2.40.0480.00615.13
7.2.30.1260.00315.23
7.2.20.1170.01314.74
7.2.10.1210.00714.82
7.2.00.1580.00315.05
7.1.220.1170.00713.80
7.1.210.0930.00713.84
7.1.200.0890.00714.04
7.1.190.0700.00713.70
7.1.180.0870.00613.57
7.1.170.0540.00614.00
7.1.160.0710.00314.11
7.1.150.1040.00313.76
7.1.140.1070.01014.11
7.1.130.1080.00613.72
7.1.120.1260.00713.91
7.1.110.1590.01014.04
7.1.100.0840.00314.01
7.1.90.1090.01014.07
7.1.80.1270.00014.05
7.1.70.1030.00614.01
7.1.60.1200.01631.90
7.1.50.1410.01331.96
7.1.40.1440.00731.78
7.1.30.0980.00332.09
7.1.20.0940.01331.63
7.1.10.1570.00713.80
7.1.00.1140.00313.59
5.6.380.0000.01013.80

preferences:
18.39 ms | 401 KiB | 5 Q