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 ) { foreach($childIds as $child) { $children = array_keys($data, $child); print_r($children); foreach ($children as $ch) { $tree['children'][] = $ch; } $childIds = $children; } } echo "\n". 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.70.0120.00318.41
8.3.60.0060.00916.75
8.3.50.0150.00722.11
8.3.40.0150.00618.97
8.3.30.0100.00319.17
8.3.20.0040.00420.35
8.3.10.0000.00723.53
8.3.00.0030.00619.25
8.2.180.0030.01318.41
8.2.170.0090.00922.96
8.2.160.0100.00320.30
8.2.150.0000.00824.18
8.2.140.0050.00324.66
8.2.130.0100.01026.16
8.2.120.0000.01022.29
8.2.110.0030.00622.15
8.2.100.0100.00318.03
8.2.90.0040.00419.31
8.2.80.0080.00018.16
8.2.70.0040.00417.75
8.2.60.0090.00018.16
8.2.50.0000.00818.07
8.2.40.0000.00818.22
8.2.30.0000.00818.07
8.2.20.0080.00017.75
8.2.10.0000.00718.13
8.2.00.0030.00717.79
8.1.280.0120.00925.92
8.1.270.0040.00423.87
8.1.260.0080.00026.35
8.1.250.0070.00028.09
8.1.240.0030.00623.83
8.1.230.0070.00319.13
8.1.220.0050.00317.79
8.1.210.0040.00418.77
8.1.200.0030.00617.35
8.1.190.0080.00017.43
8.1.180.0040.00418.10
8.1.170.0050.00318.62
8.1.160.0050.00322.07
8.1.150.0040.00418.60
8.1.140.0000.00717.46
8.1.130.0070.00017.73
8.1.120.0000.00717.47
8.1.110.0060.00317.46
8.1.100.0070.00017.35
8.1.90.0050.00317.45
8.1.80.0040.00417.48
8.1.70.0030.00317.37
8.1.60.0040.00417.55
8.1.50.0000.01017.54
8.1.40.0000.00817.41
8.1.30.0090.00017.63
8.1.20.0020.00517.63
8.1.10.0080.00017.56
8.1.00.0000.00817.48
8.0.300.0060.00318.77
8.0.290.0000.00717.18
8.0.280.0030.00318.34
8.0.270.0070.00017.26
8.0.260.0030.00317.18
8.0.250.0000.00716.95
8.0.240.0000.00716.95
8.0.230.0040.00416.96
8.0.220.0050.00216.89
8.0.210.0040.00416.90
8.0.200.0030.00316.96
8.0.190.0080.00016.90
8.0.180.0040.00416.90
8.0.170.0000.00916.88
8.0.160.0060.00316.75
8.0.150.0000.00916.88
8.0.140.0000.00816.83
8.0.130.0030.00313.24
8.0.120.0040.00416.85
8.0.110.0050.00316.80
8.0.100.0070.00016.85
8.0.90.0040.00416.89
8.0.80.0080.00716.85
8.0.70.0000.00816.68
8.0.60.0040.00416.78
8.0.50.0040.00416.88
8.0.30.0070.01217.06
8.0.20.0130.00817.40
8.0.10.0040.00417.11
8.0.00.0070.01016.82
7.4.330.0000.00515.19
7.4.320.0000.00716.54
7.4.300.0030.00316.64
7.4.290.0040.00416.58
7.4.280.0030.00316.49
7.4.270.0030.00316.54
7.4.260.0000.00716.50
7.4.250.0000.00716.49
7.4.240.0030.00316.64
7.4.230.0030.00316.73
7.4.220.0130.00816.69
7.4.210.0050.01016.60
7.4.200.0000.00816.64
7.4.190.0000.00716.49
7.4.160.0030.01316.35
7.4.150.0070.01017.40
7.4.140.0060.01417.86
7.4.130.0070.01116.56
7.4.120.0100.00716.57
7.4.110.0110.01116.53
7.4.100.0130.01016.34
7.4.90.0170.00016.42
7.4.80.0060.01319.39
7.4.70.0060.01016.53
7.4.60.0090.01216.57
7.4.50.0050.00016.36
7.4.40.0030.01022.77
7.4.30.0070.01016.50
7.4.10.0070.01014.89
7.4.00.0110.00614.94
7.3.330.0030.00313.20
7.3.320.0060.00013.38
7.3.310.0070.00016.39
7.3.300.0000.00716.33
7.3.290.0040.01116.37
7.3.280.0070.01016.35
7.3.270.0110.01117.40
7.3.260.0100.00716.60
7.3.250.0030.01416.61
7.3.240.0120.01216.33
7.3.230.0110.00616.61
7.3.210.0080.00816.39
7.3.200.0180.00719.39
7.3.190.0070.01016.45
7.3.180.0100.00716.64
7.3.170.0070.01116.44
7.3.160.0060.01016.39
7.3.130.0030.01614.86
7.3.120.0080.01014.83
7.3.110.0040.01614.89
7.3.100.0090.00314.72
7.3.90.0070.00614.95
7.3.80.0070.00914.96
7.3.70.0020.01314.69
7.3.60.0050.00814.87
7.3.50.0030.01015.03
7.3.40.0030.00914.84
7.3.30.0060.00914.64
7.3.20.0090.00216.57
7.3.10.0110.00516.52
7.3.00.0080.00516.75
7.2.330.0040.01516.73
7.2.320.0090.01616.53
7.2.310.0110.01216.73
7.2.300.0170.00616.74
7.2.290.0060.01316.63
7.2.260.0030.01514.97
7.2.250.0080.01115.01
7.2.240.0070.00715.18
7.2.230.0040.01015.34
7.2.220.0070.00815.11
7.2.210.0060.00715.13
7.2.200.0030.00915.26
7.2.190.0040.00915.22
7.2.180.0070.00515.17
7.2.170.0100.00414.93
7.2.160.0090.00514.92
7.2.150.0050.00817.16
7.2.140.0050.00816.96
7.2.130.0050.00916.96
7.2.120.0050.00716.82
7.2.110.0020.01116.82
7.2.100.0040.00916.88
7.2.90.0090.00517.04
7.2.80.0070.00516.96
7.2.70.0090.00417.05
7.2.60.0070.00516.85
7.2.50.0060.00917.11
7.2.40.0070.00616.98
7.2.30.0090.00916.92
7.2.20.0060.00517.03
7.2.10.0070.00317.09
7.2.00.0060.00917.79
7.1.330.0020.01015.82
7.1.320.0060.00415.90
7.1.310.0060.00715.77
7.1.300.0060.00815.64
7.1.290.0050.00515.91
7.1.280.0040.01115.83
7.1.270.0020.01015.71
7.1.260.0040.00915.85
7.1.250.0080.00615.77
7.1.240.0040.00715.59
7.1.230.0050.00715.77
7.1.220.0070.00715.95
7.1.210.0090.00515.90
7.1.200.0040.00615.90
7.1.190.0010.01115.68
7.1.180.0030.01015.66
7.1.170.0070.00515.73
7.1.160.0050.00715.78
7.1.150.0110.00615.97
7.1.140.0040.00715.72
7.1.130.0060.00615.66
7.1.120.0030.01015.69
7.1.110.0020.01115.66
7.1.100.0080.00316.60
7.1.90.0070.00715.77
7.1.80.0040.00715.80
7.1.70.0040.00916.26
7.1.60.0080.00716.98
7.1.50.0080.00616.11
7.1.40.0020.00915.67
7.1.30.0030.01215.75
7.1.20.0060.00615.88
7.1.10.0040.01115.69
7.1.00.0060.03018.11
7.0.330.0050.00815.52
7.0.320.0070.00615.43
7.0.310.0040.01115.23
7.0.300.0000.01015.36
7.0.290.0030.00815.24
7.0.280.0080.00715.40
7.0.270.0060.00415.29
7.0.260.0050.00815.45
7.0.250.0020.00915.59
7.0.240.0070.00615.18
7.0.230.0060.00615.23
7.0.220.0070.00215.40
7.0.210.0120.00315.23
7.0.200.0170.00415.21
7.0.190.0050.00815.35
7.0.180.0070.00815.20
7.0.170.0060.00815.33
7.0.160.0070.00515.49
7.0.150.0050.00815.47
7.0.140.0020.03417.61
7.0.130.0030.00715.46
7.0.120.0060.00815.42
7.0.110.0090.00715.23
7.0.100.0050.00815.42
7.0.90.0040.00815.56
7.0.80.0080.00515.25
7.0.70.0030.01015.46
7.0.60.0080.03216.88
7.0.50.0060.02916.38
7.0.40.0070.02815.72
7.0.30.0160.03115.56
7.0.20.0150.03015.79
7.0.10.0080.02715.84
7.0.00.0040.03215.63
5.6.400.0050.00714.25
5.6.390.0050.01114.38
5.6.380.0020.00914.63
5.6.370.0040.00814.56
5.6.360.0050.00514.31
5.6.350.0020.01514.10
5.6.340.0050.00914.53
5.6.330.0030.01014.49
5.6.320.0080.00614.60
5.6.310.0020.00714.70
5.6.300.0060.00514.62
5.6.290.0050.00814.69
5.6.280.0060.02916.58
5.6.270.0030.00914.55
5.6.260.0050.01214.42
5.6.250.0070.00814.44
5.6.240.0080.00514.65
5.6.230.0040.00514.40
5.6.220.0000.01314.21
5.6.210.0120.02716.51
5.6.200.0090.02415.84
5.6.190.0030.02016.40
5.6.180.0180.02816.51
5.6.170.0150.02916.55
5.6.160.0040.02016.47
5.6.150.0060.02515.61
5.6.140.0100.01415.80
5.6.130.0080.03215.67
5.6.120.0080.03116.54
5.6.110.0030.03616.78
5.6.100.0020.01816.66
5.6.90.0050.02016.64
5.6.80.0020.02016.42
5.6.70.1160.01716.53
5.6.60.0040.01114.36
5.6.50.0070.00714.55
5.6.40.0080.00514.28
5.6.30.0020.01114.36
5.6.20.0050.00714.49
5.6.10.0090.00114.41
5.6.00.0030.01114.40
5.5.380.0030.00814.51
5.5.370.0050.01214.47
5.5.360.0080.00714.25
5.5.350.0030.02616.36
5.5.340.0100.02215.57
5.5.330.0060.01816.52
5.5.320.0050.03416.34
5.5.310.0120.01616.36
5.5.300.0080.02815.69
5.5.290.0030.02515.65
5.5.280.0110.02516.68
5.5.270.0080.01516.60
5.5.260.0080.02516.65
5.5.250.0040.02016.46
5.5.240.0030.02816.33
5.5.230.0060.00314.47
5.5.220.0060.00814.35
5.5.210.0050.00514.50
5.5.200.0050.00914.22
5.5.190.0080.00414.40
5.5.180.0080.00514.48
5.5.170.0060.00914.38
5.5.160.0080.00814.48
5.5.150.0030.01214.46
5.5.140.0030.01014.48
5.5.130.0020.01314.46
5.5.120.0030.00914.37
5.5.110.0070.00414.39
5.5.100.0070.00714.54
5.5.90.0050.00814.49
5.5.80.0070.00714.37
5.5.70.0060.00814.31
5.5.60.0050.01014.35
5.5.50.0060.00714.51
5.5.40.0080.00514.34
5.5.30.0020.00914.46
5.5.20.0000.01314.36
5.5.10.0070.00714.18
5.5.00.0050.00914.36
5.4.450.0240.01614.42
5.4.440.0130.01514.47
5.4.430.0070.01214.42
5.4.420.0100.01914.57
5.4.410.0340.02114.51
5.4.400.0090.01314.41
5.4.390.0120.02014.33
5.4.380.0140.02514.18
5.4.370.0190.02114.23
5.4.360.0150.02314.21
5.4.350.0120.03514.38
5.4.340.0200.02114.10
5.4.330.0050.00511.93
5.4.320.0040.01612.27
5.4.310.0040.01912.23
5.4.300.0050.01512.24
5.4.290.0030.02012.25
5.4.280.0040.02012.23
5.4.270.0030.02312.21
5.4.260.0080.02712.18
5.4.250.0060.01512.12
5.4.240.0050.01912.17
5.4.230.0060.01612.13
5.4.220.0050.02012.18
5.4.210.0070.02112.17
5.4.200.0070.02112.10
5.4.190.0040.01912.14
5.4.180.0050.02312.12
5.4.170.0070.02312.11
5.4.160.0060.01912.13
5.4.150.0050.01712.14
5.4.140.0050.02112.05
5.4.130.0040.01912.00
5.4.120.0030.02112.01
5.4.110.0040.01812.03
5.4.100.0050.01912.03
5.4.90.0070.02012.00
5.4.80.0060.02111.98
5.4.70.0050.01612.08
5.4.60.0040.01612.02
5.4.50.0040.01912.07
5.4.40.0050.02011.99
5.4.30.0050.02011.96
5.4.20.0060.01811.95
5.4.10.0080.02012.02
5.4.00.0050.02311.80
5.3.290.0050.02011.93
5.3.280.0060.01811.83
5.3.270.0050.02011.96
5.3.260.0050.02011.86
5.3.250.0060.01411.88
5.3.240.0060.01511.93
5.3.230.0060.01611.93
5.3.220.0060.01611.94
5.3.210.0030.01811.93
5.3.200.0070.01811.90
5.3.190.0060.01811.96
5.3.180.0080.01811.91
5.3.170.0060.01512.00
5.3.160.0050.02411.97
5.3.150.0060.02112.00
5.3.140.0080.01911.97
5.3.130.0070.02311.95
5.3.120.0050.02311.97
5.3.110.0060.02211.91
5.3.100.0060.02111.76
5.3.90.0060.01911.79
5.3.80.0020.02211.74
5.3.70.0040.02111.73
5.3.60.0060.02311.75
5.3.50.0080.02011.72
5.3.40.0050.02511.70
5.3.30.0060.02311.69
5.3.20.0080.03211.52
5.3.10.0040.01811.43
5.3.00.0070.02111.49
5.2.170.0130.0429.19
5.2.160.0110.0359.18
5.2.150.0120.0469.18
5.2.140.0050.0439.18
5.2.130.0080.0359.14
5.2.120.0090.0409.14
5.2.110.0060.0299.14
5.2.100.0080.0329.15
5.2.90.0100.0559.15
5.2.80.0090.0409.14
5.2.70.0050.0409.14
5.2.60.0110.0389.09
5.2.50.0090.0369.07
5.2.40.0050.0299.04
5.2.30.0060.0309.02
5.2.20.0040.0319.00
5.2.10.0030.0308.92
5.2.00.0090.0278.79
5.1.60.0060.0248.07
5.1.50.0060.0258.07
5.1.40.0070.0348.04
5.1.30.0070.0318.40
5.1.20.0060.0278.41
5.1.10.0040.0288.14
5.1.00.0050.0388.14
5.0.50.0070.0276.62
5.0.40.0040.0296.48
5.0.30.0050.0336.28
5.0.20.0050.0266.26
5.0.10.0060.0266.24
5.0.00.0060.0396.23
4.4.90.0050.0144.77
4.4.80.0060.0204.75
4.4.70.0050.0204.75
4.4.60.0040.0204.75
4.4.50.0030.0234.77
4.4.40.0040.0344.71
4.4.30.0030.0224.76
4.4.20.0040.0244.85
4.4.10.0040.0224.84
4.4.00.0060.0294.76
4.3.110.0030.0194.67
4.3.100.0030.0154.66
4.3.90.0040.0134.64
4.3.80.0020.0344.58
4.3.70.0040.0144.63
4.3.60.0020.0164.63
4.3.50.0030.0164.63
4.3.40.0020.0254.54
4.3.30.0000.0183.28
4.3.20.0050.0173.26
4.3.10.0050.0143.23
4.3.00.0100.01313.47

preferences:
55.45 ms | 401 KiB | 5 Q