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 ?>