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'])); foreach ($childIds as $childId) { $children = array_keys($data, $childId); foreach ($children as $ch) { while (isset($data[$ch])) { $current = $data[$ch]; $child_id = $current === NULL ? "NULL" : $current; $tree['children'][] = $child_id; } } } 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.60.0560.12249.74
8.3.50.0400.11451.43
8.3.40.0300.05935.84
8.3.30.0370.08236.27
8.3.20.0230.02337.30
8.3.10.0110.03439.70
8.3.00.0290.01935.47
8.2.180.0700.10350.57
8.2.170.0370.07735.94
8.2.160.0210.06537.36
8.2.150.0170.03336.12
8.2.140.0170.03036.12
8.2.130.0000.03840.40
8.2.120.0030.03540.23
8.2.110.0100.05138.31
8.2.100.0260.05934.86
8.2.90.0230.05336.16
8.2.80.0160.05935.13
8.2.70.0130.05934.70
8.2.60.0230.05034.94
8.2.50.0100.06534.70
8.2.40.0070.06835.23
8.2.30.0070.06535.27
8.2.20.0100.05934.90
8.2.10.0190.05235.21
8.2.00.0130.09134.75
8.1.280.0540.06149.95
8.1.270.0170.02039.09
8.1.260.0170.02036.06
8.1.250.0130.02339.16
8.1.240.0060.02941.90
8.1.230.0240.02836.27
8.1.220.0100.03534.62
8.1.210.0170.03334.46
8.1.200.0170.03134.33
8.1.190.0130.03334.52
8.1.180.0030.04334.33
8.1.170.0100.03135.61
8.1.160.0130.03239.16
8.1.150.0160.02835.73
8.1.140.0130.03234.50
8.1.130.0100.03234.84
8.1.120.0130.03334.55
8.1.110.0200.03634.45
8.1.100.0170.03134.57
8.1.90.0140.03134.59
8.1.80.0130.03134.51
8.1.70.0160.02934.43
8.1.60.0100.03734.56
8.1.50.0130.03334.63
8.1.40.0070.04034.51
8.1.30.0100.03934.55
8.1.20.0160.02934.66
8.1.10.0340.05050.54
8.1.00.0170.07050.57
8.0.300.0200.05750.28
8.0.290.0230.05950.02
8.0.280.0200.06051.45
8.0.270.0340.05150.21
8.0.260.0200.06150.22
8.0.250.0160.06249.84
8.0.240.0230.07049.90
8.0.230.0270.06149.93
8.0.220.0330.05249.84
8.0.210.0260.05949.79
8.0.200.0360.05349.84
8.0.190.0390.05349.80
8.0.180.0200.06749.81
8.0.170.0230.06249.91
8.0.160.0260.06049.91
8.0.150.0270.06049.86
8.0.140.0130.07349.67
8.0.130.0560.12278.32
8.0.120.0300.05949.82
8.0.110.0200.06349.71
8.0.100.0160.06849.97
8.0.90.0230.05649.66
8.0.80.0390.09549.84
8.0.70.0200.06049.84
8.0.60.0170.06649.79
8.0.50.0240.06249.67
8.0.30.0580.09949.84
8.0.20.1050.13249.90
8.0.10.0170.07049.95
8.0.00.0760.10549.78
7.4.330.0150.06246.77
7.4.320.0260.05949.50
7.4.300.0190.05849.50
7.4.290.0200.06549.50
7.4.280.0400.05449.39
7.4.270.0230.05549.26
7.4.260.0100.07249.47
7.4.250.0360.04649.46
7.4.240.0290.05449.52
7.4.230.0240.05549.52
7.4.220.1300.12049.61
7.4.210.0390.11049.43
7.4.200.0200.06049.32
7.4.190.0130.07049.49
7.4.160.0300.12149.71
7.4.150.0770.08449.45
7.4.140.0650.09749.39
7.4.130.0630.09749.61
7.4.120.0650.10349.52
7.4.110.0570.09749.36
7.4.100.0960.12249.51
7.4.90.0570.09849.41
7.4.80.0650.14249.44
7.4.70.0460.10449.48
7.4.60.0500.10049.50
7.4.50.0160.06949.27
7.4.40.0100.10149.36
7.4.30.0560.09549.54
7.4.10.0290.14348.04
7.4.00.0370.11347.80
7.3.330.0400.12778.30
7.3.320.0590.13678.37
7.3.310.0140.06949.30
7.3.300.0270.05449.27
7.3.290.0570.10149.29
7.3.280.0710.13049.30
7.3.270.0550.10449.41
7.3.260.0830.12649.57
7.3.250.0460.12149.29
7.3.240.0630.14749.29
7.3.230.0650.10149.23
7.3.210.0570.09549.28
7.3.200.0810.14649.34
7.3.190.0740.16149.33
7.3.180.0640.08849.21
7.3.170.0500.10749.51
7.3.160.0450.10849.29
7.3.130.0440.13147.72
7.3.120.0450.10947.65
7.3.110.0350.09947.83
7.3.100.0320.08747.80
7.3.90.0370.10047.72
7.3.80.0420.10647.80
7.3.70.0380.08647.62
7.3.60.0320.09247.91
7.3.50.0250.11847.64
7.3.40.0400.07747.79
7.3.30.0330.10547.80
7.3.20.0210.08650.46
7.3.10.0210.09650.82
7.3.00.0670.07750.60
7.2.330.0530.12349.55
7.2.320.0780.16349.75
7.2.310.0760.08649.87
7.2.300.0630.12849.84
7.2.290.0580.19749.60
7.2.260.0260.15648.24
7.2.250.0330.11648.12
7.2.240.0430.09247.97
7.2.230.0280.12948.09
7.2.220.0380.08948.12
7.2.210.0270.10548.01
7.2.200.0380.10047.97
7.2.190.0410.10447.95
7.2.180.0410.07548.01
7.2.170.0280.09948.22
7.2.160.0260.07647.98
7.2.150.0160.07950.93
7.2.140.0100.10750.75
7.2.130.0450.09750.59
7.2.120.0200.09050.75
7.2.110.0240.08250.84
7.2.100.0100.09050.91
7.2.90.0340.10149.87
7.2.80.0250.07450.86
7.2.70.0190.08550.72
7.2.60.0490.08450.73
7.2.50.0240.10950.72
7.2.40.0570.07950.81
7.2.30.0210.08450.86
7.2.20.0150.07950.91
7.2.10.0170.08950.80
7.2.00.1510.06751.80
7.1.330.0150.14849.68
7.1.320.0160.16049.81
7.1.310.0150.16249.89
7.1.300.0150.16549.59
7.1.290.0180.15549.72
7.1.280.0130.15349.64
7.1.270.0180.17049.61
7.1.260.0550.14249.69
7.1.250.0550.17148.49
7.1.240.0170.15149.74
7.1.230.0160.15549.63
7.1.220.0150.15649.75
7.1.210.0280.15349.82
7.1.200.0240.11749.85
7.1.190.0240.14649.77
7.1.180.0200.16449.79
7.1.170.0170.16249.74
7.1.160.0180.15549.93
7.1.150.0360.17049.67
7.1.140.0100.15049.79
7.1.130.0200.14049.51
7.1.120.0250.14849.86
7.1.110.0440.16449.83
7.1.100.0160.12550.50
7.1.90.0200.14649.72
7.1.80.0270.14049.85
7.1.70.0370.11950.27
7.1.60.0150.11850.31
7.1.50.0430.14150.28
7.1.40.0180.13849.62
7.1.30.0350.14249.72
7.1.20.0220.13449.72
7.1.10.0250.15449.81
7.1.00.0390.15751.94
7.0.330.0400.15949.46
7.0.320.0150.14649.52
7.0.310.0180.15149.58
7.0.300.0180.17049.48
7.0.290.0310.15849.46
7.0.280.0490.15149.25
7.0.270.0230.15049.30
7.0.260.0140.15149.37
7.0.250.0170.14249.34
7.0.240.0180.16849.53
7.0.230.0200.13749.43
7.0.220.0080.16149.54
7.0.210.0460.15149.52
7.0.200.1520.11148.91
7.0.190.0360.15948.38
7.0.180.0350.14849.10
7.0.170.0560.14349.31
7.0.160.0510.13948.52
7.0.150.0150.13849.51
7.0.140.0390.17350.97
7.0.130.0210.15249.51
7.0.120.0260.14449.59
7.0.110.0360.14649.33
7.0.100.0420.15748.47
7.0.90.0080.16049.48
7.0.80.0320.15449.38
7.0.70.0330.16549.51
7.0.60.0210.13450.49
7.0.50.0160.15149.92
7.0.40.0190.16548.35
7.0.30.0550.15648.90
7.0.20.0610.12448.86
7.0.10.0130.14848.86
7.0.00.0240.15448.91
5.6.400.0330.25178.98
5.6.390.0500.19579.18
5.6.380.0410.20178.97
5.6.370.0230.21178.88
5.6.360.0340.19778.95
5.6.350.0340.21778.88
5.6.340.0410.19378.91
5.6.330.0340.20479.06
5.6.320.0240.23378.94
5.6.310.0340.21478.95
5.6.300.0290.20378.92
5.6.290.0370.20178.67
5.6.280.0380.20781.15
5.6.270.0290.21278.81
5.6.260.0320.20579.07
5.6.250.0360.19178.90
5.6.240.0430.19078.99
5.6.230.0350.19378.97
5.6.220.0280.23278.80
5.6.210.0310.18281.04
5.6.200.0340.19180.11
5.6.190.0340.20181.00
5.6.180.0370.19280.92
5.6.170.0430.20280.89
5.6.160.0260.21380.94
5.6.150.0380.19280.01
5.6.140.0250.19080.21
5.6.130.0310.21480.02
5.6.120.0280.20980.87
5.6.110.0290.19981.06
5.6.100.0410.20881.00
5.6.90.0330.21281.05
5.6.80.0460.18880.86
5.6.70.1280.17280.86
5.6.60.0390.20478.84
5.6.50.0370.21778.83
5.6.40.0420.20479.00
5.6.30.0280.23278.70
5.6.20.0260.21078.63
5.6.10.0350.20078.94
5.6.00.0410.23078.88
5.5.380.0420.20477.07
5.5.370.0370.20077.27
5.5.360.0370.21877.32
5.5.350.0420.18579.75
5.5.340.0340.19179.02
5.5.330.0370.21479.68
5.5.320.0390.18779.69
5.5.310.0330.19379.70
5.5.300.0270.21478.98
5.5.290.0450.19978.90
5.5.280.0400.19279.75
5.5.270.0310.22579.86
5.5.260.0420.18779.82
5.5.250.0340.21479.77
5.5.240.0370.18679.79
5.5.230.0270.24377.23
5.5.220.0400.22977.29
5.5.210.0370.21777.17
5.5.200.0310.22977.09
5.5.190.0300.22377.40
5.5.180.0480.19977.10
5.5.170.0300.22877.09
5.5.160.0370.21177.14
5.5.150.0380.22177.34
5.5.140.0310.21277.00
5.5.130.0430.19477.31
5.5.120.0310.22477.12
5.5.110.0300.22577.28
5.5.100.0470.21477.05
5.5.90.0320.22777.39
5.5.80.0380.23177.08
5.5.70.0300.24177.07
5.5.60.0360.21377.28
5.5.50.0380.20677.23
5.5.40.0430.22577.01
5.5.30.0330.22277.14
5.5.20.0310.21977.19
5.5.10.0230.22577.11
5.5.00.0330.20377.46
5.4.450.0360.21978.42
5.4.440.0830.20978.43
5.4.430.0690.21778.38
5.4.420.0750.22878.31
5.4.410.0760.20578.33
5.4.400.0570.21278.25
5.4.390.0630.22878.11
5.4.380.0880.24478.12
5.4.370.0820.25378.21
5.4.360.0750.22978.12
5.4.350.0850.22378.15
5.4.340.0730.19878.07
5.4.330.0350.18875.58
5.4.320.0310.18776.02
5.4.310.0280.20776.17
5.4.300.0300.20076.04
5.4.290.0330.20076.05
5.4.280.0300.22275.98
5.4.270.0400.21776.09
5.4.260.0280.23876.07
5.4.250.0320.22176.08
5.4.240.0430.23076.04
5.4.230.0310.22376.06
5.4.220.0280.20476.02
5.4.210.0350.19976.09
5.4.200.0350.18276.09
5.4.190.0280.21576.03
5.4.180.0320.20876.00
5.4.170.0330.20676.10
5.4.160.0350.22576.15
5.4.150.0400.22876.05
5.4.140.0380.23276.04
5.4.130.0360.22075.88
5.4.120.0450.25675.74
5.4.110.0420.23975.89
5.4.100.0340.22575.93
5.4.90.0330.20075.98
5.4.80.0380.18875.82
5.4.70.0310.26475.97
5.4.60.0440.23176.04
5.4.50.0340.25875.90
5.4.40.0380.25875.99
5.4.30.0370.25875.96
5.4.20.0280.25275.84
5.4.10.0390.24875.93
5.4.00.0370.23275.74
5.3.290.0050.02011.94
5.3.280.0060.02011.91
5.3.270.0080.03011.91
5.3.260.0060.01811.91
5.3.250.0040.01711.91
5.3.240.0060.01711.91
5.3.230.0080.02011.90
5.3.220.0090.02711.89
5.3.210.0080.02411.90
5.3.200.0090.02111.90
5.3.190.0080.02311.90
5.3.180.0040.02311.89
5.3.170.0080.02011.89
5.3.160.0060.02211.89
5.3.150.0080.01711.89
5.3.140.0090.01811.89
5.3.130.0100.03111.89
5.3.120.0090.02311.89
5.3.110.0110.02411.89
5.3.100.0020.02111.71
5.3.90.0050.01711.70
5.3.80.0080.01611.69
5.3.70.0080.01711.69
5.3.60.0070.02311.69
5.3.50.0080.02911.67
5.3.40.0100.01811.67
5.3.30.0070.02111.65
5.3.20.0050.02411.58
5.3.10.0050.02411.57
5.3.00.0060.02011.57
5.2.170.0110.01610.18
5.2.160.0090.01610.18
5.2.150.0090.01710.18
5.2.140.0110.01610.18
5.2.130.0110.01410.16
5.2.120.0070.01610.16
5.2.110.0090.01410.16
5.2.100.0040.01810.16
5.2.90.0040.01810.16
5.2.80.0050.02010.16
5.2.70.0180.04110.16
5.2.60.0060.02210.13
5.2.50.0080.02910.12
5.2.40.0030.02610.11
5.2.30.0050.02210.09
5.2.20.0120.02110.09
5.2.10.0060.02710.05
5.2.00.0080.0289.98
5.1.60.0090.0209.62
5.1.50.0060.0159.62
5.1.40.0060.0189.61
5.1.30.0080.0149.79
5.1.20.0050.0159.79
5.1.10.0120.0199.66
5.1.00.0050.0159.66
5.0.50.0070.0098.89
5.0.40.0050.0158.83
5.0.30.0030.0338.73
5.0.20.0050.0158.72
5.0.10.0060.0118.71
5.0.00.0040.0318.70
4.4.90.0030.0097.98
4.4.80.0030.0117.96
4.4.70.0040.0097.96
4.4.60.0020.0137.96
4.4.50.0020.0127.97
4.4.40.0030.0157.94
4.4.30.0020.0127.97
4.4.20.0050.0098.01
4.4.10.0030.0098.01
4.4.00.0030.0167.97
4.3.110.0010.0137.92
4.3.100.0030.0107.92
4.3.90.0020.0117.91
4.3.80.0040.0137.88
4.3.70.0050.0077.90
4.3.60.0040.0077.90
4.3.50.0030.0097.90
4.3.40.0020.0157.86
4.3.30.0070.0217.23
4.3.20.0010.0117.22
4.3.10.0030.0097.21
4.3.00.0040.00810.77

preferences:
57.88 ms | 401 KiB | 5 Q