3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tree = [ [ "id" => 1573695284631, "name" => "Cars", "pid" => 0, "children" => [ [ "id" => 1573695292010, "name" => "Audi", "pid" => 1573695284631 ], [ "id" => 1573695305619, "name" => "BMW", "pid" => 1573695284631, "children" => [ [ "id" => 1573695328137, "name" => "3 Series", "pid" => 1573695305619 ], [ "id" => 1573695335102, "name" => "X5", "pid" => 1573695305619 ] ] ] ] ], [ "id" => 1573695348647, "name" => "Motorcycles", "pid" => 0, "children" => [ [ "id" => 1573695355619, "name" => "Ducatti", "pid" => 1573695348647 ] ] ] ]; var_dump(getParentNodes($tree, 1573695335102)); function getParentNodes($haystack, $child_node_id) { foreach ($haystack as $element) { if ($element['id'] === $child_node_id) { // return [$element['id']]; // uncomment if you want to include child itself return []; } else if (array_key_exists('children', $element)) { $parentNodes = getParentNodes($element['children'], $child_node_id); if ($parentNodes !== false) { return [$element['id'], ...$parentNodes]; } } } return false; }

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.5.00.0170.00520.16
8.4.150.0020.00014.05
8.4.140.0150.00617.89
8.4.130.0130.00817.69
8.4.120.0130.00720.60
8.4.110.0140.00620.37
8.4.100.0120.01017.95
8.4.90.0110.00820.79
8.4.80.0110.00919.06
8.4.70.0040.00422.34
8.4.60.0090.00218.95
8.4.50.0120.00918.82
8.4.40.0100.00717.63
8.4.30.0150.00620.61
8.4.20.0110.01120.65
8.4.10.0030.00617.59
8.3.280.0150.01018.63
8.3.270.0140.00716.79
8.3.260.0120.00716.73
8.3.250.0130.00619.23
8.3.240.0100.00616.56
8.3.230.0140.00416.49
8.3.220.0080.01019.00
8.3.210.0090.00816.92
8.3.200.0030.00516.84
8.3.190.0060.00417.36
8.3.180.0120.00718.88
8.3.170.0070.01117.08
8.3.160.0130.00618.40
8.3.150.0070.00319.21
8.3.140.0000.00820.71
8.3.130.0150.00318.37
8.3.120.0040.00718.74
8.3.110.0080.00020.94
8.3.100.0150.00624.06
8.3.90.0080.00026.77
8.3.80.0040.00416.50
8.3.70.0120.00316.75
8.3.60.0040.01118.68
8.3.50.0070.01317.95
8.3.40.0070.01121.05
8.3.30.0080.00818.79
8.3.20.0000.00724.18
8.3.10.0080.00024.66
8.3.00.0070.00026.16
8.2.290.0140.00520.42
8.2.280.0080.00318.34
8.2.270.0110.00718.42
8.2.260.0090.00917.42
8.2.250.0030.00518.31
8.2.240.0130.01017.29
8.2.230.0030.00722.58
8.2.220.0120.00337.54
8.2.210.0040.00426.77
8.2.200.0070.00316.75
8.2.190.0150.00016.58
8.2.180.0230.00325.92
8.2.170.0110.00418.87
8.2.160.0060.00922.96
8.2.150.0080.00025.66
8.2.140.0000.00824.66
8.2.130.0040.00426.16
8.2.120.0070.00320.50
8.2.110.0050.00520.82
8.2.100.0080.00417.91
8.2.90.0050.00318.34
8.2.80.0090.00018.06
8.2.70.0040.00417.63
8.2.60.0000.00817.75
8.2.50.0040.00418.10
8.2.40.0080.00019.66
8.2.30.0050.00317.71
8.2.20.0000.00718.21
8.2.10.0050.00219.38
8.2.00.0070.00019.39
8.1.330.0110.00821.92
8.1.320.0120.00718.03
8.1.310.0090.00517.03
8.1.300.0080.00017.91
8.1.290.0090.00318.88
8.1.280.0110.01125.92
8.1.270.0080.00023.99
8.1.260.0090.00026.35
8.1.250.0080.00028.09
8.1.240.0060.00323.97
8.1.230.0040.00820.96
8.1.220.0050.00317.91
8.1.210.0040.00418.77
8.1.200.0060.00317.25
8.1.190.0040.00417.22
8.1.180.0040.00418.10
8.1.170.0000.00918.84
8.1.160.0000.00718.83
8.1.150.0050.00318.67
8.1.140.0040.00417.43
8.1.130.0000.00718.80
8.1.120.0070.00017.50
8.1.110.0040.00417.45
8.1.100.0070.00017.50
8.1.90.0070.00017.50
8.1.80.0030.00617.50
8.1.70.0000.00717.34
8.1.60.0040.00417.63
8.1.50.0030.00617.61
8.1.40.0040.00417.46
8.1.30.0040.00417.64
8.1.20.0040.00417.58
8.1.10.0040.00417.64
8.1.00.0060.00317.58
8.0.300.0040.00419.97
8.0.290.0050.00216.75
8.0.280.0000.00718.48
8.0.270.0000.00716.91
8.0.260.0060.00018.39
8.0.250.0030.00317.04
8.0.240.0030.00316.89
8.0.230.0040.00416.99
8.0.220.0000.00716.94
8.0.210.0030.00616.86
8.0.200.0040.00417.00
8.0.190.0040.00416.98
8.0.180.0070.00016.84
8.0.170.0060.00316.95
8.0.160.0100.00016.97
8.0.150.0040.00416.90
8.0.140.0000.00716.91
8.0.130.0000.00713.39
8.0.120.0040.00416.91
8.0.110.0000.00816.90
8.0.100.0040.00416.71
8.0.90.0030.00516.80
8.0.80.0040.00416.94
8.0.70.0040.00416.83
8.0.60.0050.00416.85
8.0.50.0030.00516.83
8.0.30.0000.00816.88
8.0.20.0030.00416.87
8.0.10.0010.00716.99
8.0.00.0010.00716.91
7.4.330.0050.00015.55
7.4.320.0030.00316.63
7.4.300.0000.00816.54
7.4.290.0000.00816.50
7.4.280.0070.00016.57
7.4.270.0000.00816.64
7.4.260.0000.00513.25
7.4.250.0000.00816.59
7.4.240.0040.00416.64
7.4.230.0020.00616.55
7.4.220.0040.00416.47
7.4.210.0040.00316.60
7.4.200.0000.00816.63
7.4.190.0020.00616.55
7.4.180.0060.00216.51
7.4.160.0020.00616.60
7.4.150.0050.00316.51
7.4.140.0040.00316.40
7.4.130.0020.00616.44
7.4.120.0050.00316.57
7.4.110.0040.00416.63
7.4.100.0000.00816.45
7.4.90.0030.00416.54
7.4.80.0020.00616.45
7.4.70.0030.00516.50
7.4.60.0040.00316.48
7.4.50.0030.00616.52
7.4.40.0040.00416.45
7.4.30.0040.00416.51
7.4.20.0040.00416.54
7.4.10.0040.00516.64
7.4.00.0000.00816.48
7.3.330.0000.00716.02
7.3.320.0050.00013.07
7.3.310.0030.00316.19
7.3.300.0070.00016.13
7.3.290.0040.00416.17
7.3.280.0010.00616.15
7.3.270.0000.00816.18
7.3.260.0020.00516.05
7.3.250.0060.00216.13
7.3.240.0010.00616.16
7.3.230.0010.00616.21
7.3.220.0030.00416.04
7.3.210.0040.00316.06
7.3.200.0060.00116.11
7.3.190.0000.00716.02
7.3.180.0030.00516.12
7.3.170.0010.00616.00
7.3.160.0000.00715.96
7.3.150.0040.00316.06
7.3.140.0020.00516.07
7.3.130.0020.00516.05
7.3.120.0030.00316.06
7.3.110.0020.00516.04
7.3.100.0040.00315.96
7.3.90.0000.00716.38
7.3.80.0030.00516.13
7.3.70.0020.00516.15
7.3.60.0020.00616.14
7.3.50.0060.00116.22
7.3.40.0030.00516.26
7.3.30.0040.00416.22
7.3.20.0100.00316.23
7.3.10.0040.00416.12
7.3.00.0090.00616.14

preferences:
137.18 ms | 403 KiB | 5 Q