The database output array is {code...}, which filters out cate photos. All others are retained. The effect is {code...}. How can I use array_filter to implement this? It seems that array_filter is not easy to use. The database output array is
Array ([0] => Array ([id] => 1 [name] => Hi, 234 [cate] => life diary) [1] => Array ([id] => 2 [name] => 79798 [cate] => photo photos) [2] => Array ([id] => 3 [name] => 567567 [cate] => life diary ))
In the filter, cate = photographic meitu. All others are retained. The effect is
Array ([0] => Array ([id] => 1 [name] => Hi, 234 [cate] => life diary) [1] => Array ([id] => 2 [name] => 79798 [cate] => life diary ))
How to Use array_filter? It seems that array_filter is not easy to use.
Reply content:
The database output array is
Array ([0] => Array ([id] => 1 [name] => Hi, 234 [cate] => life diary) [1] => Array ([id] => 2 [name] => 79798 [cate] => photo photos) [2] => Array ([id] => 3 [name] => 567567 [cate] => life diary ))
In the filter, cate = photographic meitu. All others are retained. The effect is
Array ([0] => Array ([id] => 1 [name] => Hi, 234 [cate] => life diary) [1] => Array ([id] => 2 [name] => 79798 [cate] => life diary ))
How to Use array_filter? It seems that array_filter is not easy to use.
Let's not talk about it, but directly code it. Unfortunately, the closure of php is as smelly and long as javascript:
$ Data = [['id' => 1, 'name' => 'hello, 000000', 'cate' => 'life diaries '], ['id' => 2, 'name' => '000000', 'cate' => 'photo meitu '], ['id' => 3, 'name' => '20140901', 'cate' => 'life diaries '],]; $ filtered = array_filter ($ data, function ($ item) {return $ item ['cate']! = 'Photo meitu ';}); print_r ($ filtered );
Note:array_filterThe second parameter. The second parameter is a user-defined function. This custom function is used to set filtering conditions.
1, 'cate' => "Life Diary"), array ('id' => 2, 'cate' => "photo"),); var_dump ($ arr ); function filter ($ rows) {if ($ rows ['cate'] = "") {return false;} else {return true ;}} $ arr = array_filter ($ arr, 'filter'); var_dump ($ arr );
I think array_filter can be used to achieve the goal.
Array ('id' => '1', 'name' => 'hello, 100', 'cate' => 'life diaries '), 1 => array ('id' => '2', 'name' => '000000', 'cate' => 'photo meitu '), 2 => array ('id' => '3', 'name' => '000000', 'cate' => 'life diaries '),); $ resultArr = array (); foreach ($ oriArr as $ key => $ value) {if ($ value ['cate'] = 'photo meitu ') {continue;} else {$ resultArr [] = $ value ;}} print_r ($ resultArr );