Skip to content
Advertisement

Filter array with array_walk_recursive but deny specific values

I am trying to filter an array

JavaScript

This returns me an array of all array-fields having id as key.

JavaScript

But there is a small problem, some of the array have an key called attribute containing an idkey field that I dont want to have.

JavaScript

Is there a way to say “don’t take the id inside attribute” ?

My current solution, I added a filter before my filter 😀

JavaScript

but this seems like this is not the best practice ^^

Advertisement

Answer

You can traverse recursively manually instead of array_walk_recursive and avoid all under attribute key.

JavaScript

Demo: https://3v4l.org/V6uFf

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement