3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getTree($treeByParent, $treeByCat, $id, $lastId) { $gTree = []; if ($id != $lastId) { $gTree[] = $id; if ( isset($treeByCat[ $id ]) && count($treeByCat[ $id ]) > 0 ) $gTree = array_merge( getTree($treeByParent, $treeByCat, $treeByCat[ $id ], $id), $gTree); if ( isset($treeByParent[ $id ]) && count($treeByParent[ $id ]) > 0 ) { foreach ($treeByParent[ $id ] as $cat) { $gTree = array_merge( getTree($treeByParent, $treeByCat, $cat, $id), $gTree); } } return $gTree; } } function display_parent_nodes($data, $id) { $tree = array( "parents" => array(), "children" => array(), "full" => array() ); $current = $data[$id]; $parent_id = $current === NULL ? "NULL" : $current; $childIds = array($id); $tree['parents'][] = $parent_id; while (isset($data[$parent_id])) { $current = $data[$parent_id]; $parent_id = $current === NULL ? "NULL" : $current; $tree['parents'][] = $parent_id; } echo implode(" > ", array_reverse($tree['parents'])); while ( count($childIds) > 0 ) { $children = array_keys($data, $childId); foreach ($children as $ch) { $current = $data[$ch]; $child_id = $current === NULL ? "NULL" : $current; $tree['children'][] = $child_id; } $childIds = $children; } echo " > ". implode(" > ", $tree['children']); } $treeByParent = array( 0 => array(1, 2), 1 => array(3, 7), 3 => array(4), 4 => array(5), 5 => array(6, 8) ); $treeByCat = array( 1 => 0, 2 => 0, 3 => 1, 7 => 1, 4 => 3, 5 => 4, 6 => 5, 8 => 5 ); print_r( display_parent_nodes($treeByCat, 4) ); //print_r( getTree($treeByParent, $treeByCat, 4, 0) );

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.40.0080.00818.79
8.3.30.0110.00419.22
8.3.20.0000.00820.19
8.3.10.0080.00023.52
8.3.00.0080.00319.38
8.2.170.0040.01122.96
8.2.160.0070.01020.47
8.2.150.0000.00824.18
8.2.140.0050.00324.66
8.2.130.0080.00026.16
8.2.120.0040.00422.08
8.2.110.0070.00320.49
8.2.100.0080.00419.66
8.2.90.0080.00019.34
8.2.80.0000.00817.97
8.2.70.0030.00617.75
8.2.60.0040.00418.04
8.2.50.0030.00618.07
8.2.40.0000.00918.28
8.2.30.0030.00518.20
8.2.20.0030.00618.00
8.2.10.0050.00318.35
8.2.00.0110.00017.95
8.1.270.0040.00422.16
8.1.260.0080.00026.35
8.1.250.0080.00028.09
8.1.240.0000.00921.06
8.1.230.0070.00419.48
8.1.220.0070.00417.74
8.1.210.0030.00618.77
8.1.200.0060.00317.35
8.1.190.0040.00417.52
8.1.180.0040.00818.10
8.1.170.0000.00918.77
8.1.160.0060.00322.06
8.1.150.0000.00918.68
8.1.140.0000.00717.64
8.1.130.0030.00317.92
8.1.120.0000.00817.65
8.1.110.0050.00617.57
8.1.100.0070.00017.57
8.1.90.0000.00717.59
8.1.80.0050.00317.57
8.1.70.0050.00517.59
8.1.60.0040.00417.71
8.1.50.0040.00417.64
8.1.40.0040.00417.55
8.1.30.0030.00517.66
8.1.20.0050.00317.75
8.1.10.0040.00417.56
8.1.00.0040.00417.56
8.0.300.0000.00918.77
8.0.290.0030.00617.17
8.0.280.0070.00218.35
8.0.270.0000.00817.30
8.0.260.0040.00417.21
8.0.250.0000.00917.14
8.0.240.0040.00417.10
8.0.230.0060.00317.04
8.0.220.0000.00916.94
8.0.210.0000.00716.95
8.0.200.0030.00617.02
8.0.190.0030.00516.91
8.0.180.0080.00016.99
8.0.170.0050.00316.95
8.0.160.0050.00216.95
8.0.150.0060.00316.95
8.0.140.0000.00816.82
8.0.130.0070.00013.53
8.0.120.0040.00416.89
8.0.110.0000.01117.00
8.0.100.0000.00816.81
8.0.90.0060.00316.82
8.0.80.0070.01316.92
8.0.70.0040.00416.82
8.0.60.0000.01016.89
8.0.50.0000.00816.91
8.0.30.0170.01617.14
8.0.20.0310.01017.40
8.0.10.0050.00316.88
8.0.00.0180.00516.78
7.4.330.0030.00315.07
7.4.320.0040.00416.63
7.4.300.0070.00016.54
7.4.290.0030.00416.52
7.4.280.0100.00016.56
7.4.270.0000.00716.60
7.4.260.0040.00416.44
7.4.250.0080.00016.30
7.4.240.0030.00416.47
7.4.230.0000.00716.47
7.4.220.0070.01316.34
7.4.210.0040.01216.43
7.4.200.0000.00716.64
7.4.190.0070.00016.59
7.4.160.0330.01816.61
7.4.150.0370.01717.40
7.4.140.0360.02217.86
7.4.130.0260.01016.46
7.4.120.0150.02316.64
7.4.110.0270.02616.63
7.4.100.0150.00416.70
7.4.90.0390.01516.58
7.4.80.0820.03519.39
7.4.70.0140.00616.56
7.4.60.0210.02216.45
7.4.50.0060.00316.28
7.4.40.0000.01322.77
7.4.30.0600.02116.78
7.3.330.0540.48278.22
7.3.320.0830.52778.25
7.3.310.0040.00416.54
7.3.300.0040.00416.39
7.3.290.0150.01516.38
7.3.280.0120.01516.35
7.3.270.0400.01317.40
7.3.260.0320.03916.71
7.3.250.0270.01316.53
7.3.240.0320.00716.53
7.3.230.0300.01316.56
7.3.210.0470.00916.71
7.3.200.0390.05019.39
7.3.190.0060.02716.45
7.3.180.0270.01216.42
7.3.170.0090.00916.40
7.3.160.0250.01516.51
7.2.330.0450.01716.74
7.2.320.0140.01416.79
7.2.310.0900.02216.69
7.2.300.0380.01916.84
7.2.290.0040.02116.79
5.4.280.0230.04719.16
5.4.270.0130.05319.34
5.4.260.0130.06019.11
5.4.250.0230.04019.27
5.4.240.0170.05019.48
5.4.230.0170.05019.27
5.4.220.0130.04019.18
5.4.210.0200.03319.14
5.4.200.0070.06019.15
5.4.190.0130.07719.13
5.4.180.0100.08719.36
5.4.170.0000.08019.39
5.4.160.0030.05719.05
5.4.150.0130.06319.45
5.4.140.0070.05716.58
5.4.130.0130.04016.60
5.4.120.0230.04016.50
5.4.110.0170.06716.74
5.4.100.0200.07016.78
5.4.90.0100.05716.86
5.4.80.0130.03716.49
5.4.70.0130.06316.55
5.4.60.0170.03316.56
5.4.50.0200.03016.43
5.4.40.0230.06316.53
5.4.30.0130.05016.80
5.4.20.0200.04016.39
5.4.10.0130.03716.34
5.4.00.0070.07716.24
5.3.280.0130.03714.75
5.3.270.0170.03714.48
5.3.260.0170.03314.61
5.3.250.0130.03714.83
5.3.240.0200.04314.51
5.3.230.0230.04314.74
5.3.220.0230.03014.54
5.3.210.0130.04014.79
5.3.200.0170.03314.50
5.3.190.0170.04014.55
5.3.180.0200.05014.56
5.3.170.0170.03714.48
5.3.160.0200.03314.58
5.3.150.0200.06014.47
5.3.140.0100.04314.77
5.3.130.0200.03714.52
5.3.120.0200.05314.52
5.3.110.0330.03714.73
5.3.100.0170.05314.04
5.3.90.0270.03713.92
5.3.80.0130.04014.09
5.3.70.0130.04013.93
5.3.60.0170.04013.91
5.3.50.0270.03313.85
5.3.40.0100.04313.86
5.3.30.0170.06013.88
5.3.20.0230.03013.71
5.3.10.0170.03313.57
5.3.00.0130.04013.61

preferences:
39.56 ms | 400 KiB | 5 Q