3v4l.org

run code in 300+ PHP versions simultaneously
<?php function build(){ $items = [ 1=>['categories_id'=>1,'name'=>'父1','parent_id'=>0], 9=>['categories_id'=>9,'name'=>'儿3-1','parent_id'=>3], 15=>['categories_id'=>15,'name'=>'儿3-1-1','parent_id'=>14], 3=>['categories_id'=>3,'name'=>'父3','parent_id'=>0], 4=>['categories_id'=>4,'name'=>'儿1-1','parent_id'=>1], 6=>['categories_id'=>6,'name'=>'儿1-3','parent_id'=>1], 12=>['categories_id'=>12,'name'=>'儿2-1-1','parent_id'=>7], 2=>['categories_id'=>2,'name'=>'父2','parent_id'=>0], 5=>['categories_id'=>5,'name'=>'儿1-2','parent_id'=>1], 8=>['categories_id'=>8,'name'=>'儿2-1','parent_id'=>2], 11=>['categories_id'=>11,'name'=>'儿1-1-1','parent_id'=>4], 7=>['categories_id'=>7,'name'=>'儿2-1','parent_id'=>2], 10=>['categories_id'=>10,'name'=>'儿3-1-1','parent_id'=>9], 13=>['categories_id'=>13,'name'=>'儿3-1-1','parent_id'=>10], 14=>['categories_id'=>14,'name'=>'儿3-1-1','parent_id'=>13], 16=>['categories_id'=>16,'name'=>'儿3-1-1','parent_id'=>10], ]; $tree = array(); foreach($items as $cid => $item){ if(isset($items[$item['parent_id']])){ // var_dump($tree); $items[$item['parent_id']]['childs'][$cid] = &$items[$cid]; }else{ $tree[$cid] = &$items[$cid]; } } return $tree; } $tree = build(); // print_r($tree); function get($tree, $level) { // static $tree; $lv = 1; $res = array(); foreach ($tree as $cid => $item) { /*if ($item['parent_id'] == 0) { if ($lv == $level) { continue; } $res[$cid] = $item; $lv ++; }*/ var_dump($item); if ($item['parent_id'] == 0) { $lv = 1; } if (is_array($item)) { $lv ++; return get($item, $level); } var_dump($lv); } } $get = get($tree, 2); // var_dump($get);

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.0110.00716.63
8.3.50.0040.01116.64
8.3.40.0130.00718.88
8.3.30.0080.00818.84
8.3.20.0000.00819.32
8.3.10.0030.00519.27
8.3.00.0030.00519.68
8.2.180.0120.00318.42
8.2.170.0090.00922.96
8.2.160.0080.00820.82
8.2.150.0040.00424.18
8.2.140.0050.00324.66
8.2.130.0070.00019.82
8.2.120.0040.00426.35
8.2.110.0000.01022.09
8.2.100.0070.01117.78
8.2.90.0000.00918.00
8.2.80.0000.00818.76
8.2.70.0050.00318.05
8.2.60.0040.00418.03
8.2.50.0040.00418.10
8.2.40.0030.00621.18
8.2.30.0030.00519.60
8.2.20.0060.00318.02
8.2.10.0030.00518.05
8.2.00.0030.00319.52
8.1.280.0100.00725.92
8.1.270.0040.00423.92
8.1.260.0080.00026.35
8.1.250.0080.00028.09
8.1.240.0100.00023.96
8.1.230.0080.00419.00
8.1.220.0000.00818.70
8.1.210.0040.00418.77
8.1.200.0050.00317.38
8.1.190.0000.00817.25
8.1.180.0060.00318.10
8.1.170.0000.00818.47
8.1.160.0030.00618.91
8.1.150.0020.00518.90
8.1.140.0080.00017.71
8.1.130.0040.00419.08
8.1.120.0000.00817.40
8.1.110.0040.00417.45
8.1.100.0040.00417.47
8.1.90.0080.00017.36
8.1.80.0030.00617.37
8.1.70.0040.00417.41
8.1.60.0040.00417.64
8.1.50.0030.00517.58
8.1.40.0030.00517.49
8.1.30.0030.00917.60
8.1.20.0060.00317.56
8.1.10.0040.00417.50
8.1.00.0030.00717.38
8.0.300.0000.00818.77
8.0.290.0090.00016.63
8.0.280.0040.00418.37
8.0.270.0000.00717.21
8.0.260.0000.00718.93
8.0.250.0000.00716.94
8.0.240.0050.00216.92
8.0.230.0030.00316.91
8.0.220.0070.00017.01
8.0.210.0040.00416.87
8.0.200.0040.00417.03
8.0.190.0000.00717.04
8.0.180.0000.00817.00
8.0.170.0060.00616.99
8.0.160.0040.00417.07
8.0.150.0020.01016.92
8.0.140.0040.00416.81
8.0.130.0000.00813.41
8.0.120.0000.00717.02
8.0.110.0040.00416.87
8.0.100.0000.00817.01
8.0.90.0000.00716.87
8.0.80.0080.01116.89
8.0.70.0040.00416.97
8.0.60.0030.00517.02
8.0.50.0000.00816.96
8.0.30.0150.00817.03
8.0.20.0110.00817.40
8.0.10.0040.00417.16
8.0.00.0100.01216.63
7.4.330.0060.00015.55
7.4.320.0030.00316.51
7.4.300.0030.00316.63
7.4.290.0030.00316.64
7.4.280.0050.00316.51
7.4.270.0000.00716.49
7.4.260.0040.00316.45
7.4.250.0000.00716.63
7.4.240.0020.00516.45
7.4.230.0030.00316.65
7.4.220.0000.00816.69
7.4.210.0110.00516.45
7.4.200.0000.00716.46
7.4.160.0100.01016.49
7.4.140.0180.00717.86
7.4.130.0070.01416.65
7.4.120.0090.01116.53
7.4.110.0110.01116.41
7.4.100.0070.01116.61
7.4.90.0160.00716.44
7.4.80.0110.00919.39
7.4.70.0130.01016.43
7.4.60.0060.01316.65
7.4.50.0030.01216.47
7.4.40.0000.01916.75
7.4.10.0030.01714.77
7.4.00.0050.00915.02
7.3.330.0000.00613.30
7.3.320.0000.00613.40
7.3.310.0040.00416.47
7.3.300.0000.00716.29
7.3.290.0000.00716.35
7.3.280.0070.00916.42
7.3.260.0110.01016.51
7.3.240.0110.00916.43
7.3.230.0140.00716.63
7.3.210.0150.01216.45
7.3.200.0100.01016.38
7.3.190.0110.00716.41
7.3.180.0150.00316.50
7.3.170.0140.00416.64
7.3.160.0130.00516.46
7.3.130.0040.01415.12
7.3.120.0060.01215.07
7.3.110.0060.01314.90
7.3.100.0090.00614.82
7.3.90.0070.00714.87
7.3.80.0040.00814.89
7.3.70.0030.01014.68
7.3.60.0060.00914.80
7.3.50.0040.00715.07
7.3.40.0070.01014.67
7.3.30.0100.00714.72
7.3.20.0070.00716.49
7.3.10.0100.00616.54
7.3.00.0040.00816.70
7.2.330.0130.01316.43
7.2.320.0080.01516.83
7.2.310.0080.01216.84
7.2.300.0060.01416.80
7.2.290.0100.01016.69
7.2.260.0130.00615.13
7.2.250.0040.01515.25
7.2.240.0000.01115.16
7.2.230.0040.01115.29
7.2.220.0040.01115.14
7.2.210.0080.00615.19
7.2.200.0030.01015.21
7.2.190.0070.00315.05
7.2.180.0040.01515.31
7.2.170.0070.01015.22
7.2.160.0040.00715.16
7.2.150.0080.00417.02
7.2.140.0030.00817.04
7.2.130.0030.01316.77
7.2.120.0030.01217.00
7.2.110.0100.00616.71
7.2.100.0040.00716.87
7.2.90.0030.00916.93
7.2.80.0080.00616.75
7.2.70.0070.01117.07
7.2.60.1610.00616.27
7.2.50.1340.01016.13
7.2.40.1410.01116.43
7.2.30.1410.00916.40
7.2.20.1170.00816.33
7.2.10.1280.00616.32
7.2.00.1490.00916.35
7.1.330.0030.01015.87
7.1.320.0000.01815.86
7.1.310.0070.01016.06
7.1.300.0110.00015.91
7.1.290.0110.00315.78
7.1.280.0060.00315.79
7.1.270.0080.00815.84
7.1.260.0030.01215.91
7.1.250.0130.00115.66
7.1.240.0030.00915.57
7.1.230.0120.00315.58
7.1.220.0030.00615.76
7.1.210.0030.01315.78
7.1.200.0060.00815.66
7.1.190.0090.00615.98
7.1.180.0030.00915.88
7.1.170.2180.00814.61
7.1.160.2030.01616.36
7.1.150.2280.00916.34
7.1.140.1530.00616.36
7.1.130.2410.01116.47
7.1.120.1930.01116.13
7.1.110.2390.00815.90
7.1.100.1920.01115.90
7.1.90.3470.01016.06
7.1.80.3370.00915.95
7.1.70.2920.00915.41
7.1.60.2770.01524.46
7.1.50.3660.01424.51
7.1.40.4390.00924.16
7.1.30.4780.01524.20
7.1.20.3120.00924.33
7.1.10.2110.01115.33
7.1.00.2090.01015.32
7.0.330.0000.01015.42
7.0.320.0050.00515.27
7.0.310.0060.00315.48
7.0.300.0090.00015.25
7.0.290.0040.00715.56
7.0.280.0080.00815.10
7.0.270.0000.01515.39
7.0.260.0090.00615.54
7.0.250.0070.01015.61
7.0.240.0030.00915.43
7.0.230.0000.01315.21
7.0.220.0030.01015.52
7.0.210.0000.01315.39
7.0.200.0080.00415.50
7.0.190.0040.01115.57
7.0.180.0040.00415.62
7.0.170.0090.00015.31
7.0.160.0040.00815.54
7.0.150.0110.00315.47
7.0.140.0030.00915.46
7.0.130.0000.01715.47
7.0.120.0030.01415.61
7.0.110.0060.00315.23
7.0.100.0060.00615.61
7.0.90.0030.01415.55
7.0.80.0030.01415.59
7.0.70.0110.00015.34
7.0.60.0060.01015.47
7.0.50.0060.01015.16
7.0.40.0050.00513.45
7.0.30.0100.00313.57
7.0.20.0000.00913.48
7.0.10.0030.00613.52
7.0.00.0090.00313.52
5.6.400.0070.00714.48
5.6.390.0030.00914.46
5.6.380.0030.01014.71
5.6.370.0060.01014.36
5.6.360.0110.00314.59
5.6.350.0090.00614.34
5.6.340.0120.00614.52
5.6.330.0080.00814.50
5.6.320.0040.00414.36
5.6.310.0110.00414.06
5.6.300.0100.00314.18
5.6.290.0100.00314.42
5.6.280.0040.01114.64
5.6.270.0130.00814.49
5.6.260.0070.00714.29
5.6.250.0030.01514.73
5.6.240.0100.00614.37
5.6.230.0030.00714.37
5.6.220.0030.00914.58
5.6.210.0030.01214.43
5.6.200.0000.01414.75
5.6.190.0040.00714.27
5.6.180.0030.00614.30
5.6.170.0060.00914.57
5.6.160.0080.00414.43
5.6.150.0000.01414.60
5.6.140.0030.01014.39
5.6.130.0000.01314.68
5.6.120.0070.00714.67
5.6.110.0070.00714.29
5.6.100.0030.00614.34
5.6.90.0000.01414.62
5.6.80.0000.01414.18
5.6.70.0060.00914.71
5.6.60.0060.00314.20
5.6.50.0030.00914.50
5.6.40.0000.01814.46
5.6.30.0030.01414.50
5.6.20.0090.00614.64
5.6.10.0090.00614.58
5.6.00.0040.00814.57

preferences:
53.27 ms | 400 KiB | 5 Q