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); foreach ($children as $ch) { $current = $data[$ch]; $child_id = $current === NULL ? "NULL" : $current; $tree['children'][] = $child_id; } $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.40.0140.00018.66
8.3.30.0070.00719.22
8.3.20.0080.00020.14
8.3.10.0040.00423.70
8.3.00.0000.00819.38
8.2.170.0120.00322.96
8.2.160.0040.01620.39
8.2.150.0090.00024.18
8.2.140.0040.00424.66
8.2.130.0000.00726.16
8.2.120.0070.00022.32
8.2.110.0070.00319.08
8.2.100.0040.00717.84
8.2.90.0030.00519.34
8.2.80.0040.00417.97
8.2.70.0040.00417.75
8.2.60.0060.00318.05
8.2.50.0060.00318.07
8.2.40.0000.00817.92
8.2.30.0040.00418.20
8.2.20.0040.00417.75
8.2.10.0000.00718.17
8.2.00.0070.00417.68
8.1.270.0050.00323.97
8.1.260.0030.00626.35
8.1.250.0040.00428.09
8.1.240.0030.00621.37
8.1.230.0080.00417.58
8.1.220.0000.00817.74
8.1.210.0080.00018.77
8.1.200.0060.00317.35
8.1.190.0040.00417.39
8.1.180.0030.00518.10
8.1.170.0050.00318.46
8.1.160.0000.00722.03
8.1.150.0000.00818.66
8.1.140.0000.00817.46
8.1.130.0040.00417.91
8.1.120.0030.00417.41
8.1.110.0080.00017.51
8.1.100.0070.00017.54
8.1.90.0030.00317.54
8.1.80.0040.00417.51
8.1.70.0030.00317.41
8.1.60.0040.00417.55
8.1.50.0040.00417.53
8.1.40.0040.00417.54
8.1.30.0000.00817.63
8.1.20.0050.00317.61
8.1.10.0070.00017.57
8.1.00.0040.00417.49
8.0.300.0040.00418.77
8.0.290.0000.00716.63
8.0.280.0070.00018.48
8.0.270.0030.00317.34
8.0.260.0070.00017.32
8.0.250.0040.00416.99
8.0.240.0030.00316.89
8.0.230.0040.00416.93
8.0.220.0080.00016.81
8.0.210.0030.00316.79
8.0.200.0000.00616.96
8.0.190.0030.00516.98
8.0.180.0050.00216.91
8.0.170.0040.00416.83
8.0.160.0000.00716.94
8.0.150.0050.00216.91
8.0.140.0000.00716.88
8.0.130.0000.00713.43
8.0.120.0000.00816.76
8.0.110.0000.00716.88
8.0.100.0000.00816.95
8.0.90.0070.00016.85
8.0.80.0070.00716.86
8.0.70.0040.00416.80
8.0.60.0030.00516.95
8.0.50.0040.00416.78
8.0.30.0080.01117.21
8.0.20.0090.01317.40
8.0.10.0040.00417.06
8.0.00.0130.00616.88
7.4.330.0000.00515.00
7.4.320.0060.00016.52
7.4.300.0030.00316.61
7.4.290.0040.00416.51
7.4.280.0040.00416.64
7.4.270.0030.00416.52
7.4.260.0000.00716.53
7.4.250.0030.00316.44
7.4.240.0050.00216.59
7.4.230.0000.00716.72
7.4.220.0030.01416.54
7.4.210.0090.00916.60
7.4.200.0080.00016.43
7.4.190.0070.00016.76
7.4.160.0000.01516.41
7.4.150.0070.01117.40
7.4.140.0080.01017.86
7.4.130.0090.00716.45
7.4.120.0070.01016.41
7.4.110.0130.00316.41
7.4.100.0090.00916.42
7.4.90.0110.00616.41
7.4.80.0030.01619.39
7.4.70.0130.00316.48
7.4.60.0070.01016.39
7.4.50.0000.00416.52
7.4.40.0100.00722.77
7.4.30.0080.01316.46
7.4.00.0110.00715.11
7.3.330.0030.00313.25
7.3.320.0000.00613.40
7.3.310.0040.00416.38
7.3.300.0000.00716.37
7.3.290.0100.00816.37
7.3.280.0080.00816.38
7.3.270.0120.01217.40
7.3.260.0120.00916.45
7.3.250.0050.01516.47
7.3.240.0130.00716.38
7.3.230.0100.00716.67
7.3.210.0100.00716.67
7.3.200.0100.01319.39
7.3.190.0130.00416.32
7.3.180.0090.00916.32
7.3.170.0080.00816.40
7.3.160.0070.01016.41
7.3.120.0130.00814.84
7.3.110.0000.01614.83
7.3.100.0000.01114.57
7.3.90.0070.01114.66
7.3.80.0000.00914.64
7.3.70.0060.00914.80
7.3.60.0040.00414.89
7.3.50.0100.01014.45
7.3.40.0070.00714.83
7.3.30.0070.00714.88
7.3.20.0070.00716.31
7.3.10.0110.00716.57
7.3.00.0080.00416.67
7.2.330.0110.00716.92
7.2.320.0140.00516.71
7.2.310.0160.00316.61
7.2.300.0090.01016.67
7.2.290.0040.01916.68
7.2.240.0000.01714.94
7.2.230.0130.00314.88
7.2.220.0070.01115.02
7.2.210.0030.01314.98
7.2.200.0100.00314.97
7.2.190.0100.00715.01
7.2.180.0070.00715.02
7.2.170.0030.01315.03
7.2.160.0130.00015.10
7.2.150.0070.01116.75
7.2.140.0030.01316.84
7.2.130.0100.00316.79
7.2.120.0060.00916.90
7.2.110.0070.00717.02
7.2.100.0060.00616.63
7.2.90.0040.00416.92
7.2.80.0040.00816.98
7.2.70.0000.01516.86
7.2.60.0040.00916.86
7.2.50.0030.00616.80
7.2.40.0000.01016.83
7.2.30.0000.01416.98
7.2.20.0140.00316.93
7.2.10.0130.00316.75
7.2.00.0020.01318.03
7.1.330.0070.00715.83
7.1.320.0070.00715.73
7.1.310.0040.01115.70
7.1.300.0080.00815.46
7.1.290.0070.00715.55
7.1.280.0060.01015.52
7.1.270.0040.01115.46
7.1.260.0030.01415.80
7.1.250.0080.00415.72
7.1.200.0120.00015.90
7.1.100.0030.00817.88
7.1.70.0100.00317.14
7.1.60.0150.00619.33
7.1.50.0090.01316.78
7.1.00.0100.07322.42
7.0.200.0220.00614.94
7.0.140.0000.07321.95
7.0.60.0130.07019.88
7.0.50.0100.08017.93
7.0.40.0070.04020.20
7.0.30.0500.07020.10
7.0.20.0230.04720.22
7.0.10.0200.08720.26
7.0.00.0000.05020.09
5.6.280.0000.07721.01
5.6.210.0000.04320.57
5.6.200.0130.07718.16
5.6.190.0070.09020.47
5.6.180.0230.04320.48
5.6.170.0330.07720.53
5.6.160.0070.08320.50
5.6.150.0070.08318.29
5.6.140.0070.08018.23
5.6.130.0030.09018.14
5.6.120.0230.07321.05
5.6.110.0270.07321.04
5.6.100.0070.07020.91
5.6.90.0070.07721.02
5.6.80.0100.07720.39
5.6.70.0370.03020.39
5.5.350.0200.06020.40
5.5.340.0070.08017.96
5.5.330.0030.08020.57
5.5.320.0300.07020.27
5.5.310.0270.04320.27
5.5.300.0030.06017.93
5.5.290.0070.05317.97
5.5.280.0000.05320.76
5.5.270.0030.08020.79
5.5.260.0100.08320.88
5.5.250.0070.06720.70
5.5.240.0170.07720.25
5.4.450.0800.06319.59
5.4.440.0900.07319.17
5.4.430.0400.06319.38
5.4.420.0930.05719.70
5.4.410.0630.05719.42
5.4.400.0400.06019.29
5.4.390.0770.05719.31
5.4.380.0330.05318.75
5.4.370.0370.07318.79
5.4.360.0430.06318.58
5.4.350.0270.06018.84
5.4.340.0430.06318.74
5.4.320.0080.04212.52
5.4.310.0100.03512.51
5.4.300.0060.04112.52
5.4.290.0060.03812.52
5.4.280.0090.05612.38
5.4.270.0060.05312.38
5.4.260.0090.06112.38
5.4.250.0100.06312.38
5.4.240.0130.09712.38
5.4.230.0190.09612.37
5.4.220.0150.06212.38
5.4.210.0170.08212.38
5.4.200.0180.10412.38
5.4.190.0120.07612.37
5.4.180.0190.08012.37
5.4.170.0130.06812.38
5.4.160.0130.05312.38
5.4.150.0100.04912.37
5.4.140.0120.05012.05
5.4.130.0080.04712.04
5.4.120.0080.06112.00
5.4.110.0100.04812.00
5.4.100.0090.04512.00
5.4.90.0070.05212.00
5.4.80.0060.05212.00
5.4.70.0120.04712.00
5.4.60.0050.04912.00
5.4.50.0140.04411.99
5.4.40.0110.04611.98
5.4.30.0120.04611.98
5.4.20.0100.04811.98
5.4.10.0080.04911.98
5.4.00.0100.04711.47
5.3.290.0050.04812.80
5.3.280.0110.04712.71
5.3.270.0100.05412.72
5.3.260.0110.04912.72
5.3.250.0120.05312.72
5.3.240.0130.06512.72
5.3.230.0090.05812.71
5.3.220.0150.06412.68
5.3.210.0220.07012.68
5.3.200.0100.05412.68
5.3.190.0100.05212.68
5.3.180.0140.05812.67
5.3.170.0350.10912.67
5.3.160.0160.05012.67
5.3.150.0130.05112.67
5.3.140.0100.04712.66
5.3.130.0100.05212.66
5.3.120.0160.05212.66
5.3.110.0150.06512.66
5.3.100.0160.05512.12
5.3.90.0120.05512.08
5.3.80.0110.05112.07
5.3.70.0160.04612.08
5.3.60.0070.05312.06
5.3.50.0130.04712.00
5.3.40.0100.05412.00
5.3.30.0120.04511.95
5.3.20.0060.05411.74
5.3.10.0110.04711.71
5.3.00.0090.05511.69
5.2.170.0090.0489.18
5.2.160.0060.0439.18
5.2.150.0110.0399.18
5.2.140.0100.0439.18
5.2.130.0090.0459.14
5.2.120.0080.0399.14
5.2.110.0070.0399.15
5.2.100.0070.0429.15
5.2.90.0100.0399.14
5.2.80.0070.0479.14
5.2.70.0140.0539.14
5.2.60.0130.0619.10
5.2.50.0140.0709.07
5.2.40.0090.0599.04
5.2.30.0190.0659.02
5.2.20.0150.0509.01
5.2.10.0060.0458.92
5.2.00.0050.0538.79
5.1.60.0070.0378.07
5.1.50.0090.0358.07
5.1.40.0080.0388.04
5.1.30.0020.0358.39
5.1.20.0060.0278.41
5.1.10.0220.0588.15
5.1.00.0130.0728.14
5.0.50.0070.0356.62
5.0.40.0070.0386.48
5.0.30.0080.0666.29
5.0.20.0080.0416.26
5.0.10.0150.0396.24
5.0.00.0110.0536.23
4.4.90.0080.0444.78
4.4.80.0070.0254.75
4.4.70.0040.0224.75
4.4.60.0040.0224.76
4.4.50.0100.0334.77
4.4.40.0090.0434.71
4.4.30.0070.0184.76
4.4.20.0080.0154.84
4.4.10.0010.0194.85
4.4.00.0020.0264.76
4.3.110.0040.0164.67
4.3.100.0030.0164.66
4.3.90.0040.0164.64
4.3.80.0090.0254.59
4.3.70.0040.0254.63
4.3.60.0040.0234.62
4.3.50.0050.0224.63
4.3.40.0050.0504.54
4.3.30.0000.0183.29
4.3.20.0020.0163.27
4.3.10.0040.0143.24
4.3.00.0300.01310.37

preferences:
44.93 ms | 400 KiB | 5 Q