Skip to content
Advertisement

Tag: array-filter

PHP Array_filter on “simple” multi-level array

Can I and how can I use PHP’s array_filter to filter the blank/nulls entries out of the following array structure? From: The array is from a PDO call using Fetch BOTH so the numeric and named values are always equal in this case. To: I have tried plain old array_filter array_filter(array, function($f){ ??? }) and not quite sure where to

PHP – How to remove empty entries of an array recursively?

I need to remove empty entries on multilevel arrays. For now I can remove entries with empty sub-arrays, but not empty arrays… confused, so do I… I think the code will help to explain better… Ok, this code will remove “nickname”, “birthdate” but is not removing “bikes” that have an empty array. My question is… How to remove the “bikes”

How to run array_filter recursively in a PHP array?

Given the following array $mm When I run count(array_filter($mm)) I get 3 as result since it is not recursive. count(array_filter($mm), COUNT_RECURSIVE) also will not do because I actually need to run the array_filter recursively, and then count its result. So my question is: how do I recursively run array_filter($mm) in this case? My expected result here would be 4. Please

Advertisement