Filter ArrayObject (PHP)
array-filter, arrayobject, php
Solution
How about you export it to an actual array, and then create a new Array Object?
$my_data = new ArrayObject(array(1,2,3));
$result = new ArrayObject(
array_filter( (array) $my_data, function($item) {
return $item !== 2;
})
);
Problem
I have my data in `ArrayObject`, simply representing an array. I need to filter the data, function `array_filter()` would work great. However, it does not work with `ArrayObject` as argument. What's the best way to treat with this? Is there any standard function which handles filtering for me? Example: ``` $my_data = ArrayObject(array(1,2,3)); $result = array_object_filter($my_data, function($item) { return $item !== 2; }); ``` Is there any `array_object_filter` function?