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; $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 $child_id) { $children = array_keys($data, $child); while (isset($data[$children])) { $current = $data[$children]; $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.0060.00918.55
8.3.50.0090.01121.98
8.3.40.0130.00319.09
8.3.30.0090.00919.27
8.3.20.0030.00520.34
8.3.10.0000.00823.67
8.3.00.0000.00819.38
8.2.180.0120.00318.41
8.2.170.0000.01422.96
8.2.160.0030.01020.55
8.2.150.0030.00524.18
8.2.140.0000.00824.66
8.2.130.0070.00726.16
8.2.120.0040.00422.20
8.2.110.0080.00322.30
8.2.100.0070.00417.91
8.2.90.0000.00719.17
8.2.80.0040.00418.02
8.2.70.0060.00317.63
8.2.60.0060.00317.93
8.2.50.0030.00518.07
8.2.40.0030.00618.22
8.2.30.0050.00218.14
8.2.20.0040.00417.89
8.2.10.0040.00418.13
8.2.00.0070.00317.81
8.1.280.0070.01025.92
8.1.270.0060.00322.07
8.1.260.0030.00526.35
8.1.250.0050.00328.09
8.1.240.0030.00623.64
8.1.230.0120.00019.10
8.1.220.0000.00917.74
8.1.210.0050.00318.77
8.1.200.0030.00617.35
8.1.190.0090.00017.41
8.1.180.0040.00418.10
8.1.170.0050.00318.51
8.1.160.0060.00322.02
8.1.150.0000.00718.55
8.1.140.0040.00417.47
8.1.130.0070.00017.83
8.1.120.0070.00017.51
8.1.110.0080.00317.46
8.1.100.0070.00017.36
8.1.90.0040.00417.48
8.1.80.0000.00717.49
8.1.70.0000.00717.45
8.1.60.0090.00017.55
8.1.50.0050.00317.47
8.1.40.0050.00517.52
8.1.30.0000.00817.63
8.1.20.0050.00217.64
8.1.10.0070.00017.46
8.1.00.0080.00017.54
8.0.300.0040.00418.77
8.0.290.0070.00017.05
8.0.280.0070.00018.39
8.0.270.0000.00817.14
8.0.260.0030.00317.14
8.0.250.0030.00316.96
8.0.240.0030.00317.07
8.0.230.0000.00816.91
8.0.220.0000.00816.86
8.0.210.0070.00016.95
8.0.200.0000.00616.91
8.0.190.0040.00417.06
8.0.180.0030.00616.99
8.0.170.0030.00516.89
8.0.160.0040.00417.01
8.0.150.0040.00416.89
8.0.140.0050.00316.89
8.0.130.0000.00613.35
8.0.120.0030.00516.95
8.0.110.0050.00316.93
8.0.100.0030.00516.76
8.0.90.0070.00016.89
8.0.80.0120.00416.94
8.0.70.0050.00216.91
8.0.60.0050.00316.82
8.0.50.0000.00816.95
8.0.30.0130.00616.97
8.0.20.0120.01017.40
8.0.10.0000.00717.13
8.0.00.0080.01016.83
7.4.330.0050.00015.00
7.4.320.0030.00316.46
7.4.300.0070.00016.61
7.4.290.0070.00016.51
7.4.280.0000.00716.48
7.4.270.0030.00316.51
7.4.260.0050.00316.51
7.4.250.0040.00416.55
7.4.240.0050.00316.50
7.4.230.0000.00716.42
7.4.220.0070.01016.59
7.4.210.0050.01116.50
7.4.200.0070.00016.52
7.4.190.0000.00716.56
7.4.160.0130.00316.53
7.4.150.0120.00617.40
7.4.140.0110.00817.86
7.4.130.0090.00816.55
7.4.120.0080.00916.69
7.4.110.0070.01116.67
7.4.100.0120.00616.65
7.4.90.0110.00516.48
7.4.80.0060.01819.39
7.4.70.0070.01016.64
7.4.60.0120.00316.43
7.4.50.0040.00416.20
7.4.40.0090.00922.77
7.4.30.0090.00616.50
7.4.10.0130.00615.04
7.4.00.0030.01414.87
7.3.330.0020.00213.44
7.3.320.0060.00013.43
7.3.310.0030.00516.52
7.3.300.0040.00416.48
7.3.290.0060.00916.36
7.3.280.0070.01016.44
7.3.270.0120.00617.40
7.3.260.0090.00816.63
7.3.250.0130.00816.44
7.3.240.0060.01216.41
7.3.230.0130.00316.43
7.3.210.0110.00616.38
7.3.200.0080.01319.39
7.3.190.0090.00916.57
7.3.180.0120.00416.60
7.3.170.0030.01316.60
7.3.160.0040.01216.64
7.3.130.0090.00914.71
7.3.120.0050.01114.81
7.3.110.0100.01014.73
7.3.100.0090.00314.90
7.3.90.0100.01014.98
7.3.80.0070.00314.98
7.3.70.0000.01514.92
7.3.60.0090.00314.91
7.3.50.0100.00314.77
7.3.40.0030.00614.84
7.3.30.0070.00714.92
7.3.20.0040.00716.67
7.3.10.0060.00616.53
7.3.00.0040.00816.65
7.2.330.0070.01116.84
7.2.320.0060.01216.79
7.2.310.0090.01316.75
7.2.300.0120.00616.92
7.2.290.0060.01316.79
7.2.260.0090.00915.32
7.2.250.0090.00915.34
7.2.240.0060.00315.00
7.2.230.0030.01415.33
7.2.220.0140.00715.22
7.2.210.0000.01514.90
7.2.200.0000.01615.23
7.2.190.0000.01514.96
7.2.180.0060.00615.21
7.2.170.0030.01015.06
7.2.160.0120.00014.95
7.2.150.0130.00317.00
7.2.140.0100.00317.00
7.2.130.0000.01517.03
7.2.120.0060.01017.00
7.2.110.0070.00716.91
7.2.100.0070.00416.94
7.2.90.0060.01016.78
7.2.80.0120.00016.98
7.2.70.0070.00717.02
7.2.60.0100.00317.08
7.2.50.0070.00316.85
7.2.40.0060.00317.04
7.2.30.0030.00717.04
7.2.20.0120.00317.02
7.2.10.0100.01017.12
7.2.00.0050.01118.04
7.1.330.0040.01215.77
7.1.320.0070.01115.86
7.1.310.0060.01116.14
7.1.300.0100.00315.73
7.1.290.0060.00315.89
7.1.280.0070.00715.81
7.1.270.0040.00715.44
7.1.260.0040.01115.64
7.1.250.0040.01116.00
7.1.240.0090.00615.64
7.1.230.0110.00415.84
7.1.220.0030.01115.70
7.1.210.0030.01415.63
7.1.200.0070.01015.55
7.1.190.0090.00015.75
7.1.180.0000.01215.95
7.1.170.0100.00015.96
7.1.160.0000.01315.83
7.1.150.0060.00615.63
7.1.140.0070.01315.91
7.1.130.0030.01015.67
7.1.120.0070.00715.78
7.1.110.0070.00416.00
7.1.100.0030.01216.94
7.1.90.0030.01415.86
7.1.80.0120.00315.92
7.1.70.0040.00716.22
7.1.60.0080.00717.48
7.1.50.0000.01816.53
7.1.40.0030.00915.91
7.1.30.0000.01615.79
7.1.20.0100.00315.80
7.1.10.0070.00315.76
7.1.00.0040.04418.98
7.0.330.0060.00715.11
7.0.320.0130.00015.45
7.0.310.0120.00015.41
7.0.300.0090.00315.56
7.0.290.0030.01015.39
7.0.280.0120.00315.18
7.0.270.0030.00715.50
7.0.260.0030.01015.18
7.0.250.0100.00315.54
7.0.240.0030.00715.62
7.0.230.0000.01615.53
7.0.220.0060.00915.10
7.0.210.0030.01015.51
7.0.200.0550.00615.16
7.0.190.0030.00915.48
7.0.180.0040.01115.30
7.0.170.0070.00715.27
7.0.160.0120.00315.23
7.0.150.0040.00415.36
7.0.140.0000.04518.60
7.0.130.0030.01015.60
7.0.120.0060.00315.25
7.0.110.0030.01515.47
7.0.100.0100.00715.64
7.0.90.0030.00915.57
7.0.80.0030.00915.56
7.0.70.0100.00315.24
7.0.60.0020.04317.63
7.0.50.0040.04616.77
7.0.40.0070.04316.65
7.0.30.0150.03916.83
7.0.20.0170.02516.90
7.0.10.0110.04216.85
7.0.00.0030.04916.80
5.6.400.0040.01114.51
5.6.390.0110.00814.59
5.6.380.0080.00814.37
5.6.370.0150.00014.75
5.6.360.0090.00014.59
5.6.350.0000.01314.45
5.6.340.0090.00614.70
5.6.330.0070.00414.70
5.6.320.0060.00314.34
5.6.310.0050.00514.74
5.6.300.0070.00714.67
5.6.290.0040.01114.88
5.6.280.0020.04617.88
5.6.270.0060.00914.57
5.6.260.0110.00314.57
5.6.250.0030.00714.24
5.6.240.0070.00714.60
5.6.230.0060.00614.43
5.6.220.0070.00314.41
5.6.210.0000.02717.50
5.6.200.0030.03816.48
5.6.190.0090.03917.61
5.6.180.0080.04617.52
5.6.170.0130.02717.35
5.6.160.0070.02217.49
5.6.150.0070.04516.40
5.6.140.0070.04516.38
5.6.130.0090.02816.37
5.6.120.0090.04517.74
5.6.110.0070.04417.74
5.6.100.0020.03917.62
5.6.90.0050.02517.85
5.6.80.0050.04517.30
5.6.70.0260.02117.49
5.6.60.0030.01014.48
5.6.50.0040.01114.17
5.6.40.0040.00714.30
5.6.30.0070.00714.41
5.6.20.0100.00314.07
5.6.10.0120.00314.20
5.6.00.0040.01114.34
5.5.380.0090.00014.45
5.5.370.0070.00714.52
5.5.360.0030.00614.70
5.5.350.0050.03617.35
5.5.340.0080.04016.34
5.5.330.0110.03417.53
5.5.320.0140.02217.34
5.5.310.0120.03117.42
5.5.300.0020.03116.17
5.5.290.0060.02816.25
5.5.280.0020.03117.73
5.5.270.0030.04217.63
5.5.260.0090.03517.46
5.5.250.0020.04217.49
5.5.240.0120.04017.47
5.5.230.0070.00714.38
5.5.220.0040.00814.39
5.5.210.0030.01014.43
5.5.200.0070.00314.34
5.5.190.0030.00614.32
5.5.180.0000.01014.43
5.5.170.0000.01114.35
5.5.160.0000.00914.44
5.5.150.0110.00413.96
5.5.140.0030.01314.55
5.5.130.0090.00314.25
5.5.120.0030.00914.69
5.5.110.0070.00714.51
5.5.100.0070.00714.49
5.5.90.0130.00314.50
5.5.80.0030.00514.51
5.5.70.0040.00414.27
5.5.60.0070.00414.18
5.5.50.0030.01114.26
5.5.40.0040.00814.17
5.5.30.0080.00414.09
5.5.20.0040.00814.47
5.5.10.0030.01014.23
5.5.00.0090.00614.02
5.4.450.0450.02516.29
5.4.440.0380.05116.30
5.4.430.0230.03716.14
5.4.420.0420.04016.15
5.4.410.0330.03216.07
5.4.400.0270.02816.13
5.4.390.0580.02516.06
5.4.380.0500.03315.74
5.4.370.0430.03015.72
5.4.360.0530.03215.89
5.4.350.0560.02615.75
5.4.340.0470.03315.84
5.4.330.0030.01012.97
5.4.320.0040.02612.74
5.4.310.0060.02012.74
5.4.300.0050.02812.74
5.4.290.0060.02312.74
5.4.280.0080.02412.68
5.4.270.0040.03112.67
5.4.260.0060.02912.68
5.4.250.0080.02512.68
5.4.240.0090.03212.68
5.4.230.0120.03012.67
5.4.220.0080.02412.67
5.4.210.0090.02612.67
5.4.200.0100.02812.67
5.4.190.0070.03012.67
5.4.180.0070.02912.67
5.4.170.0090.02912.67
5.4.160.0100.02412.67
5.4.150.0070.02812.67
5.4.140.0060.02912.51
5.4.130.0050.03012.51
5.4.120.0130.02912.48
5.4.110.0080.02712.48
5.4.100.0080.02712.48
5.4.90.0060.02912.48
5.4.80.0090.02312.48
5.4.70.0060.01912.48
5.4.60.0040.02812.48
5.4.50.0080.03112.48
5.4.40.0090.02012.48
5.4.30.0090.02312.47
5.4.20.0040.02212.47
5.4.10.0060.01912.47
5.4.00.0070.02112.22
5.3.290.0060.02912.89
5.3.280.0030.02312.84
5.3.270.0060.02312.85
5.3.260.0060.02212.85
5.3.250.0070.02212.85
5.3.240.0050.02112.84
5.3.230.0040.02412.84
5.3.220.0040.02512.82
5.3.210.0080.03312.82
5.3.200.0080.03012.83
5.3.190.0100.04012.82
5.3.180.0090.02712.82
5.3.170.0130.05612.82
5.3.160.0100.03812.82
5.3.150.0070.03312.82
5.3.140.0110.04912.82
5.3.130.0100.04512.81
5.3.120.0070.02812.81
5.3.110.0070.02312.81
5.3.100.0160.07412.54
5.3.90.0140.06112.53
5.3.80.0120.04112.52
5.3.70.0130.03812.52
5.3.60.0100.03512.52
5.3.50.0070.03212.48
5.3.40.0080.04812.48
5.3.30.0110.03712.46
5.3.20.0140.06512.35
5.3.10.0060.04412.34
5.3.00.0050.04212.33
5.2.170.0120.0409.19
5.2.160.0090.0359.18
5.2.150.0110.0449.18
5.2.140.0060.0369.18
5.2.130.0140.0629.14
5.2.120.0110.0379.14
5.2.110.0120.0429.14
5.2.100.0180.0559.14
5.2.90.0180.0689.14
5.2.80.0170.0739.14
5.2.70.0180.0649.13
5.2.60.0120.0449.09
5.2.50.0070.0409.07
5.2.40.0080.0409.04
5.2.30.0100.0449.02
5.2.20.0120.0449.01
5.2.10.0160.0388.92
5.2.00.0100.0508.78
5.1.60.0130.0378.07
5.1.50.0090.0388.07
5.1.40.0090.0368.04
5.1.30.0120.0608.39
5.1.20.0120.0738.42
5.1.10.0080.0378.14
5.1.00.0060.0398.14
5.0.50.0140.0496.62
5.0.40.0080.0276.48
5.0.30.0100.0676.29
5.0.20.0130.0326.26
5.0.10.0060.0226.24
5.0.00.0090.0416.23
4.4.90.0040.0244.77
4.4.80.0070.0224.76
4.4.70.0050.0174.75
4.4.60.0100.0184.76
4.4.50.0030.0204.77
4.4.40.0030.0324.70
4.4.30.0040.0164.76
4.4.20.0030.0204.84
4.4.10.0040.0204.85
4.4.00.0050.0304.76
4.3.110.0060.0174.67
4.3.100.0060.0194.66
4.3.90.0080.0134.63
4.3.80.0040.0254.59
4.3.70.0050.0194.63
4.3.60.0110.0384.63
4.3.50.0060.0304.63
4.3.40.0070.0394.54
4.3.30.0040.0233.28
4.3.20.0080.0283.26
4.3.10.0050.0213.23
4.3.00.0130.01710.37

preferences:
48.76 ms | 401 KiB | 5 Q