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.40.0130.00718.77
8.3.30.0110.00418.72
8.3.20.0040.00419.27
8.3.10.0080.00019.24
8.3.00.0090.00019.69
8.2.170.0150.00422.96
8.2.160.0120.00320.83
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0040.00419.83
8.2.120.0070.00026.35
8.2.110.0030.00622.15
8.2.100.0040.00717.91
8.2.90.0060.00317.88
8.2.80.0050.00318.96
8.2.70.0060.00318.03
8.2.60.0000.00918.04
8.2.50.0000.00818.10
8.2.40.0000.00821.15
8.2.30.0000.00719.50
8.2.20.0000.00818.12
8.2.10.0000.00818.15
8.2.00.0000.00719.55
8.1.270.0000.00723.85
8.1.260.0030.00526.35
8.1.250.0070.00028.09
8.1.240.0080.00423.68
8.1.230.0000.01121.03
8.1.220.0040.00418.61
8.1.210.0080.00018.77
8.1.200.0040.00417.35
8.1.190.0040.00417.22
8.1.180.0080.00018.10
8.1.170.0080.00018.50
8.1.160.0000.00719.03
8.1.150.0040.00418.78
8.1.140.0040.00417.67
8.1.130.0000.00818.93
8.1.120.0000.00717.35
8.1.110.0030.00517.50
8.1.100.0040.00417.51
8.1.90.0050.00317.48
8.1.80.0000.00817.41
8.1.70.0000.00717.47
8.1.60.0000.00917.48
8.1.50.0000.00717.44
8.1.40.0050.00317.53
8.1.30.0000.00917.61
8.1.20.0030.00617.70
8.1.10.0000.00817.60
8.1.00.0050.00517.52
8.0.300.0030.00518.77
8.0.290.0040.00416.75
8.0.280.0070.00018.41
8.0.270.0000.00817.25
8.0.260.0000.00719.13
8.0.250.0040.00416.98
8.0.240.0030.00317.02
8.0.230.0030.00316.93
8.0.220.0040.00416.92
8.0.210.0080.00017.03
8.0.200.0040.00417.07
8.0.190.0030.00516.96
8.0.180.0000.00816.89
8.0.170.0090.00316.99
8.0.160.0030.00516.96
8.0.150.0100.00016.88
8.0.140.0030.00316.84
8.0.130.0040.00413.33
8.0.120.0040.00416.93
8.0.110.0020.00516.86
8.0.100.0050.00316.92
8.0.90.0040.00416.91
8.0.80.0140.00517.03
8.0.70.0050.00217.00
8.0.60.0050.00216.84
8.0.50.0050.00316.76
8.0.30.0110.00717.21
8.0.20.0120.00717.40
8.0.10.0000.00717.04
8.0.00.0160.00316.78
7.4.330.0000.00515.55
7.4.320.0000.00616.64
7.4.300.0030.00516.62
7.4.290.0040.00416.51
7.4.280.0030.00616.60
7.4.270.0040.00416.64
7.4.260.0030.00316.48
7.4.250.0000.00816.45
7.4.240.0000.00716.53
7.4.230.0030.00316.43
7.4.220.0090.00016.41
7.4.210.0120.00516.67
7.4.200.0000.00716.63
7.4.160.0090.00816.64
7.4.140.0110.00917.86
7.4.130.0090.01216.72
7.4.120.0090.01116.55
7.4.110.0110.00716.57
7.4.100.0060.01016.66
7.4.90.0040.01416.58
7.4.80.0110.00719.39
7.4.70.0130.00916.39
7.4.60.0030.01816.70
7.4.50.0090.00516.56
7.4.40.0070.01016.67
7.4.00.0070.01014.65
7.3.330.0000.00513.39
7.3.320.0000.00613.37
7.3.310.0000.00716.45
7.3.300.0030.00316.37
7.3.290.0070.00016.37
7.3.280.0030.01216.39
7.3.260.0070.01216.41
7.3.240.0100.00816.56
7.3.230.0120.00816.36
7.3.210.0080.01516.50
7.3.200.0100.00716.65
7.3.190.0160.00016.30
7.3.180.0060.00916.34
7.3.170.0060.01116.47
7.3.160.0080.00816.63
7.2.330.0120.00616.59
7.2.320.0060.01316.49
7.2.310.0130.00716.70
7.2.300.0030.01316.57
7.2.290.0080.01516.79
7.2.60.3030.00614.76
7.2.50.3120.00815.12
7.2.40.3300.00715.50
7.2.30.3760.00715.35
7.2.20.2310.01015.47
7.2.10.3210.00815.21
7.2.00.3460.00715.29
7.1.200.0000.01015.80
7.1.170.3240.00714.13
7.1.160.3410.01016.89
7.1.150.3760.01616.92
7.1.140.3060.01217.02
7.1.130.2840.01116.89
7.1.120.3740.01116.69
7.1.110.2010.00815.83
7.1.100.2470.01115.93
7.1.90.3780.00816.52
7.1.80.3440.01116.13
7.1.70.3890.00715.09
7.1.60.3200.01333.23
7.1.50.5490.01233.09
7.1.40.5010.01632.55
7.1.30.5950.01132.78
7.1.20.3910.01432.78
7.1.10.4140.00714.98
7.1.00.4850.01014.96

preferences:
64.04 ms | 400 KiB | 5 Q