The database output array is
Array( [0] => Array ( [id] => 1 [name] => 你好,234 [cate] => 生活日记 ) [1] => Array ( [id] => 2 [name] => 79798 [cate] => 摄影美图 ) [2] => Array ( [id] => 3 [name] => 567567 [cate] => 生活日记 ))
Filter inside Cate = Photographic beauty, all other reservations, the effect is
Array( [0] => Array ( [id] => 1 [name] => 你好,234 [cate] => 生活日记 ) [1] => Array ( [id] => 2 [name] => 79798 [cate] => 生活日记 ))
How to implement it with Array_filter? Feel array_filter not very useful.
Reply content:
The database output array is
Array( [0] => Array ( [id] => 1 [name] => 你好,234 [cate] => 生活日记 ) [1] => Array ( [id] => 2 [name] => 79798 [cate] => 摄影美图 ) [2] => Array ( [id] => 3 [name] => 567567 [cate] => 生活日记 ))
Filter inside Cate = Photographic beauty, all other reservations, the effect is
Array( [0] => Array ( [id] => 1 [name] => 你好,234 [cate] => 生活日记 ) [1] => Array ( [id] => 2 [name] => 79798 [cate] => 生活日记 ))
How to implement it with Array_filter? Feel array_filter not very useful.
Do not say anything, directly on the code, unfortunately, PHP's closure and JS like the same smelly and long:
$data = [ [ 'id' => 1, 'name' => '你好,234', 'cate' => '生活日记'], [ 'id' => 2, 'name' => '79798', 'cate' => '摄影美图'], [ 'id' => 3, 'name' => '567567', 'cate' => '生活日记'],];$filtered = array_filter($data, function($item){ return $item['cate'] !== '摄影美图'; });print_r($filtered);
Note array_filter
The second argument, the second parameter is a custom function. This custom function is intended to set the filter criteria.
1, 'cate'=>"生活日记"), array('id'=>2, 'cate'=>"摄影美图"), ); var_dump($arr); function filter($rows){ if($rows['cate']==="摄影美图"){ return false; }else{ return true; } } $arr = array_filter($arr, 'filter'); var_dump($arr);
I don't think it's possible to do it without array_filter.
array('id' => '1', 'name' => '你好,234', 'cate' => '生活日记'), 1 => array('id' => '2', 'name' => '79798', 'cate' => '摄影美图'), 2 => array('id' => '3', 'name' => '567567', 'cate' => '生活日记'), ); $resultArr = array(); foreach ($oriArr as $key => $value) { if ($value['cate'] === '摄影美图') { continue; } else { $resultArr[] = $value; } } print_r($resultArr);