function mfilter($list, $method, $negate)libphutil Technical Documentation (Core Utilities)
function mfilter($list, $method, $negate)
libphutil Technical Documentation (Core Utilities)
Filter a list of objects by executing a method across all the objects and filter out the ones with empty() results. this function works just like ifilter(), except that it operates on a list of objects instead of a list of arrays.
For example, to remove all objects with no children from a list, where 'hasChildren' is a method name, do this:
mfilter($list, 'hasChildren');
The optional third parameter allows you to negate the operation and filter out nonempty objects. To remove all objects that DO have children, do this:
mfilter($list, 'hasChildren', true);
Parameters
array | $list | List of objects to filter. |
string | $method | A method name. |
bool | $negate | Optionally, pass true to drop objects which pass the filter instead of keeping them. |
Return
array | List of objects which pass the filter. |
- Defined
- src/utils/utils.php:523