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.70.0060.01018.55
8.3.60.0100.01016.75
8.3.50.0120.00316.35
8.3.40.0150.00018.79
8.3.30.0110.00418.79
8.3.20.0030.00619.24
8.3.10.0040.00419.23
8.3.00.0080.00019.79
8.2.190.0070.00716.75
8.2.180.0040.01118.66
8.2.170.0140.00422.96
8.2.160.0140.00021.00
8.2.150.0080.00024.18
8.2.140.0040.00424.66
8.2.130.0080.00019.89
8.2.120.0040.00426.35
8.2.110.0000.01022.25
8.2.100.0130.00019.64
8.2.90.0000.00817.75
8.2.80.0090.00018.92
8.2.70.0030.00618.04
8.2.60.0000.00817.93
8.2.50.0000.00818.10
8.2.40.0030.00621.07
8.2.30.0070.00019.43
8.2.20.0070.00018.14
8.2.10.0000.00818.09
8.2.00.0070.00019.52
8.1.280.0080.01125.92
8.1.270.0040.00424.01
8.1.260.0070.00026.35
8.1.250.0080.00028.09
8.1.240.0100.00023.91
8.1.230.0040.00718.95
8.1.220.0000.00818.55
8.1.210.0000.00818.77
8.1.200.0030.00617.25
8.1.190.0040.00417.35
8.1.180.0050.00318.10
8.1.170.0050.00318.65
8.1.160.0000.00818.82
8.1.150.0000.00718.91
8.1.140.0080.00017.74
8.1.130.0070.00019.00
8.1.120.0050.00217.50
8.1.110.0040.00417.41
8.1.100.0050.00317.46
8.1.90.0030.00517.38
8.1.80.0080.00017.34
8.1.70.0050.00217.49
8.1.60.0000.00917.59
8.1.50.0040.00417.56
8.1.40.0030.00617.54
8.1.30.0000.01017.72
8.1.20.0060.00317.64
8.1.10.0000.00817.56
8.1.00.0040.00417.55
8.0.300.0040.00418.77
8.0.290.0040.00416.75
8.0.280.0000.00718.46
8.0.270.0040.00417.20
8.0.260.0040.00419.09
8.0.250.0080.00017.09
8.0.240.0030.00317.02
8.0.230.0030.00517.07
8.0.220.0040.00416.96
8.0.210.0000.00717.02
8.0.200.0060.00017.00
8.0.190.0000.00717.06
8.0.180.0000.00816.84
8.0.170.0090.00317.07
8.0.160.0040.00416.97
8.0.150.0080.00316.83
8.0.140.0070.00016.99
8.0.130.0030.00313.45
8.0.120.0000.00716.97
8.0.110.0000.00816.81
8.0.100.0070.00016.85
8.0.90.0030.00516.86
8.0.80.0090.00916.95
8.0.70.0040.00416.96
8.0.60.0000.00817.11
8.0.50.0080.00016.81
8.0.30.0100.00917.22
8.0.20.0070.01217.40
8.0.10.0040.00417.16
8.0.00.0090.00916.68
7.4.330.0050.00015.55
7.4.320.0030.00316.65
7.4.300.0030.00316.54
7.4.290.0030.00316.67
7.4.280.0000.00716.53
7.4.270.0070.00016.65
7.4.260.0030.00316.52
7.4.250.0000.00816.63
7.4.240.0040.00416.58
7.4.230.0030.00316.50
7.4.220.0040.00416.69
7.4.210.0050.01216.58
7.4.200.0040.00416.37
7.4.160.0060.01116.47
7.4.140.0110.00917.86
7.4.130.0070.01016.57
7.4.120.0100.01316.59
7.4.110.0060.01316.54
7.4.100.0140.00316.53
7.4.90.0140.01016.65
7.4.80.0080.01519.39
7.4.70.0110.01116.58
7.4.60.0100.00716.37
7.4.50.0060.01016.68
7.4.40.0000.01616.65
7.4.00.0070.01015.09
7.3.330.0020.00213.27
7.3.320.0030.00313.47
7.3.310.0030.00316.50
7.3.300.0000.00716.45
7.3.290.0030.00316.46
7.3.280.0120.00616.47
7.3.260.0130.00516.54
7.3.240.0100.00816.61
7.3.230.0090.00916.46
7.3.210.0160.01116.46
7.3.200.0110.00816.48
7.3.190.0080.00816.61
7.3.180.0120.00816.37
7.3.170.0100.01016.46
7.3.160.0070.01116.39
7.2.330.0100.00716.60
7.2.320.0090.01216.73
7.2.310.0050.01416.72
7.2.300.0030.01316.79
7.2.290.0100.01416.66
7.2.60.2790.00515.11
7.2.50.3420.00715.02
7.2.40.3200.00915.41
7.2.30.2360.00615.49
7.2.20.2520.00915.46
7.2.10.3500.00915.33
7.2.00.2690.00915.36
7.1.200.0060.00616.01
7.1.170.4470.01013.79
7.1.160.2980.00716.98
7.1.150.2070.01216.91
7.1.140.3530.01316.43
7.1.130.3480.01116.99
7.1.120.3910.00916.63
7.1.110.2530.01215.89
7.1.100.3000.00715.87
7.1.90.2130.01116.16
7.1.80.3460.01116.42
7.1.70.3150.01115.23
7.1.60.3040.01133.33
7.1.50.3820.02033.13
7.1.40.4290.01432.59
7.1.30.4250.01232.71
7.1.20.3660.01832.57
7.1.10.2590.01214.87
7.1.00.2150.01014.96

preferences:
83.91 ms | 401 KiB | 5 Q