PHP 数组根据某个字段分组

 1 <?php
 2 
 3     $arr = [
 4         [
 5             'id'=>1,
 6              'name'=>'Tom'
 7         ],
 8         [
 9             'id'=>2,
10              'name'=>'Tom'
11         ],
12         [
13             'id'=>3,
14              'name'=>'Tom'
15         ],
16         [
17             'id'=>4,
18              'name'=>'Tom'
19         ],
20         [
21             'id'=>5,
22              'name'=>'Tom'
23         ]
24     ];
25     $arr1 = array_filter($arr,function($val){return $val['id'] < 3;});
26     $arr2 = array_filter($arr,function($val){return $val['id'] > 3;});
27     var_dump($arr2);exit;
28     
29 ?>

 

posted @ 2020-08-07 13:29  糖糖Y  阅读(2440)  评论(0编辑  收藏  举报