3v4l.org

run code in 300+ PHP versions simultaneously
<?php global $array; $array = [ '0' => [ 'id' => 1, 'parent' => 0, 'name' => 'root 0' ], '1' => [ 'id' => 2, 'parent' => 1, 'name' => 'root 1' ], '2' => [ 'id' => 3, 'parent' => 2, // this should have after parse parent 1 'name' => 'root 2' ], '3' => [ 'id' => 4, 'parent' => 3, // this should have after parse parent 1 'name' => 'root 3' ], '4' => [ 'id' => 5, 'parent' => 3, // this should have after parse parent 1 'name' => 'root 4' ], '5' => [ 'id' => 6, 'parent' => 2, // this should have after parse parent 1 'name' => 'root 2' ] ]; global $new_array; $new_array = []; foreach( $array as $item ) { if( $item['parent'] == 0 ) { $new_array[] = $item; // if parent 0 - clone into new array continue; } //echo $item['name'] . PHP_EOL; $temp = check_parent( $item['parent'] ); // get child $item['parent'] = $temp['id']; $new_array[] = $item; } echo '<pre>'; print_r($new_array); function check_parent( $parent ) { //echo '- check for parent of ' . $parent . PHP_EOL; global $array; foreach( $array as $item ) { if( $item['id'] == $parent && $item['parent'] == 0 ) { //echo '[OK] found root parent id: ' . $item['id'] . PHP_EOL; $item['parent'] = $item['id']; return $item; } else { return check_parent( $item['id'] ); } } }

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.4.120.0130.00720.77
8.4.110.0120.00918.59
8.4.100.0120.00817.54
8.4.90.0140.00717.55
8.4.80.0050.00419.50
8.4.70.0120.00817.75
8.4.60.0040.00418.79
8.4.50.0050.00420.45
8.4.40.0040.00419.45
8.4.30.0130.00620.21
8.4.20.0000.01918.72
8.4.10.0040.00717.91
8.3.250.0080.00917.37
8.3.240.0150.00516.63
8.3.230.0110.00816.70
8.3.220.0090.00920.99
8.3.210.0110.00716.62
8.3.200.0070.00216.63
8.3.190.0090.01017.13
8.3.180.0100.00916.74
8.3.170.0070.00019.13
8.3.160.0070.00716.60
8.3.150.0110.00720.80
8.3.140.0040.00419.01
8.3.130.0050.00318.46
8.3.120.0050.00520.75
8.3.110.0100.01020.94
8.3.100.0030.00516.76
8.3.90.0000.00826.77
8.3.80.0030.00617.97
8.3.70.0090.00918.55
8.3.60.0060.01318.55
8.3.50.0140.00217.30
8.3.40.0060.00918.78
8.3.30.0120.00418.64
8.3.20.0070.00020.48
8.3.10.0000.00822.05
8.3.00.0060.00322.34
8.2.290.0110.00118.86
8.2.280.0120.00420.36
8.2.270.0100.01017.22
8.2.260.0120.00616.50
8.2.250.0080.00016.75
8.2.240.0030.00516.91
8.2.230.0000.00822.58
8.2.220.0100.00024.06
8.2.210.0110.00426.77
8.2.200.0040.00716.50
8.2.190.0120.00316.68
8.2.180.0040.01116.63
8.2.170.0090.00619.04
8.2.160.0110.00422.07
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0000.00826.16
8.2.120.0000.00821.08
8.2.110.0000.00920.98
8.2.100.0040.00817.91
8.2.90.0080.00017.84
8.2.80.0000.00817.97
8.2.70.0030.00617.59
8.2.60.0030.00617.93
8.2.50.0090.00018.07
8.2.40.0060.00318.16
8.2.30.0080.00018.03
8.2.20.0000.00718.09
8.2.10.0000.00719.56
8.2.00.0040.00419.30
8.1.330.0130.00616.13
8.1.320.0090.01315.89
8.1.310.0030.01418.39
8.1.300.0050.00517.60
8.1.290.0000.01030.84
8.1.280.0070.01025.92
8.1.270.0080.00823.97
8.1.260.0040.00426.35
8.1.250.0110.00428.09
8.1.240.0060.00321.03
8.1.230.0110.00022.70
8.1.220.0000.00817.74
8.1.210.0060.00318.98
8.1.200.0030.00617.35
8.1.190.0000.00817.13
8.1.180.0000.00818.10
8.1.170.0030.00618.69
8.1.160.0030.00518.95
8.1.150.0080.00318.77
8.1.140.0070.00020.26
8.1.130.0000.00720.14
8.1.120.0050.00217.48
8.1.110.0050.00217.47
8.1.100.0070.00417.51
8.1.90.0040.00417.46
8.1.80.0030.00317.42
8.1.70.0030.00317.48
8.1.60.0000.00817.54
8.1.50.0050.00317.49
8.1.40.0140.00517.49
8.1.30.0170.00317.60
8.1.20.0180.00517.58
8.1.10.0180.00517.51
8.1.00.0160.00417.51
8.0.300.0040.00420.04
8.0.290.0020.00516.63
8.0.280.0000.00718.45
8.0.270.0000.00816.82
8.0.260.0060.00321.86
8.0.250.0030.00616.95
8.0.240.0000.00716.98
8.0.230.0030.00316.96
8.0.220.0000.00816.79
8.0.210.0030.00316.85
8.0.200.0060.00016.90
8.0.190.0040.00316.84
8.0.180.0030.00516.92
8.0.170.0140.00516.87
8.0.160.0140.00416.88
8.0.150.0120.00616.83
8.0.140.0110.00716.82
8.0.130.0150.00315.89
8.0.120.0100.00816.85
8.0.110.0120.00516.85
8.0.100.0140.00316.79
8.0.90.0140.00416.82
8.0.80.0130.00616.85
8.0.70.0120.00716.77
8.0.60.0140.00616.89
8.0.50.0140.00516.81
8.0.30.0170.00516.88
8.0.20.0110.00916.92
8.0.10.0130.00516.95
8.0.00.0120.00316.99
7.4.330.0000.00515.55
7.4.320.0030.00316.58
7.4.300.0070.00016.50
7.4.290.0160.00916.54
7.4.280.0170.00316.55
7.4.270.0120.00616.54
7.4.260.0140.00415.69
7.4.250.0130.00716.48
7.4.240.0100.00516.52
7.4.230.0090.00416.53
7.4.220.0080.00416.59
7.4.210.0100.00616.57
7.4.200.0070.00516.61
7.4.190.0090.00416.56
7.4.180.0150.00216.64
7.4.160.0120.00616.45
7.4.150.0110.00316.47
7.4.140.0110.00516.42
7.4.130.0130.00616.44
7.4.120.0140.00616.45
7.4.110.0140.00616.44
7.4.100.0150.00616.53
7.4.90.0130.00716.48
7.4.80.0150.00517.16
7.4.70.0150.00416.42
7.4.60.0130.00716.45
7.4.50.0130.00616.44
7.4.40.0120.00816.34
7.4.30.0140.00616.36
7.4.20.0150.00616.40
7.4.10.0140.00716.44
7.4.00.0140.00416.06
7.3.330.0130.00416.33
7.3.320.0120.00315.56
7.3.310.0150.00216.40
7.3.300.0100.00716.33
7.3.290.0120.00516.33
7.3.280.0130.00616.30
7.3.270.0140.00616.32
7.3.260.0110.00616.41
7.3.250.0160.00416.35
7.3.240.0140.00616.39
7.3.230.0160.00316.41
7.3.220.0150.00416.28
7.3.210.0150.00516.32
7.3.200.0160.00516.28
7.3.190.0150.00516.36
7.3.180.0150.00616.26
7.3.170.0150.00516.29
7.3.160.0150.00516.28
7.3.150.0200.00216.20
7.3.140.0160.00516.29
7.3.130.0160.00416.28
7.3.120.0200.00216.18
7.3.110.0160.00516.18
7.3.100.0260.00515.62
7.3.90.0230.00615.89
7.3.80.0160.00515.63
7.3.70.0140.00715.68
7.3.60.0100.01016.03
7.3.50.0170.00316.05
7.3.40.0150.00515.97
7.3.30.0130.00716.02
7.3.20.0280.00417.44
7.3.10.0300.00217.36
7.3.00.0300.00517.40
7.2.340.0180.00416.43
7.2.330.0140.00716.56
7.2.320.0130.00916.54
7.2.310.0160.00516.45
7.2.300.0170.00516.42
7.2.290.0140.00616.46
7.2.280.0180.00516.40
7.2.270.0170.00516.43
7.2.260.0180.00416.43
7.2.250.0150.00816.37
7.2.240.0210.00316.38
7.2.230.0160.00516.46
7.2.220.0140.00615.97
7.2.210.0110.00815.78
7.2.200.0130.00715.97
7.2.190.0110.00816.12
7.2.180.0150.00416.15
7.2.170.0140.00616.22
7.2.160.0160.00416.22
7.2.150.0240.00817.71
7.2.140.0250.00617.57
7.2.130.0280.00417.60
7.2.120.0280.00417.63
7.2.110.0250.00617.59
7.2.100.0240.00817.72
7.2.90.0280.00717.59
7.2.80.0300.00317.59
7.2.70.0300.00617.56
7.2.60.0330.00517.54
7.2.50.0290.00417.54
7.2.40.0270.00717.69
7.2.30.0260.00617.68
7.2.20.0260.00617.60
7.2.10.0260.00817.61
7.2.00.0240.00817.63
7.1.330.0170.00517.33
7.1.320.0430.00415.92
7.1.310.0300.00316.07
7.1.300.0250.00516.60
7.1.290.0250.00516.56
7.1.280.0240.00616.58
7.1.270.0280.00316.35
7.1.260.0270.00416.51
7.1.250.0240.00616.46
7.1.240.0150.00517.31
7.1.230.0160.00417.33
7.1.220.0120.00917.29
7.1.210.0160.00517.38
7.1.200.0140.00617.29
7.1.190.0150.00417.32
7.1.180.0180.00217.31
7.1.170.0160.00417.27
7.1.160.0170.00317.31
7.1.150.0190.00117.30
7.1.140.0160.00517.23
7.1.130.0130.00717.28
7.1.120.0180.00417.33
7.1.110.0120.00817.30
7.1.100.0200.00417.28
7.1.90.0150.00517.23
7.1.80.0180.00417.44
7.1.70.0160.00517.19
7.1.60.0150.00517.36
7.1.50.0150.00517.37
7.1.40.0140.00517.34
7.1.30.0180.00417.39
7.1.20.0120.00817.19
7.1.10.0130.00717.42
7.1.00.0150.00517.22

preferences:
29.02 ms | 403 KiB | 5 Q