Skip to content
Advertisement

Tag: recursion

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

PHP recursive search and replace array elements

I want to recursively search and replace elements in an array. The array is tree based so looks like etc. I want to be able to replace certain items with other items, so for example, I want to replace all entries in the array (at whatever depth level) of type A with an array of type B. But here’s the

Advertisement