I have an array of objects. The objects have a is_valid method that has some internal logic and returns either a boolean.
Now I want to get all objects in the array that return true to is_valid. I can do it using a foreach loop.
But is there way to do it using array_filter in PHP without creating a new anonymous or callback function?
array_reducewill reduce your array to a single value you can use array_filter instead and pass youris_validmethod to itarray_reduceandarray_filter. I was basically looking for a way to filter an array of objects without creating a callback function.