Skip to content
Advertisement

multidimensional array remove item from child array

i have a problem with my multidimensional array. I want to remove some items from child array by $id value.

here is my multidimensional example array and selectedIds:

JavaScript

and i want to remove from array those items which are not in selectedIds array.

so i want to have output:

JavaScript

i try to make it with foreach and array_key_exist but its not correct:

JavaScript

this outpus is only item with id 30

Advertisement

Answer

write else part into your code if array has no children key

JavaScript

Final code

JavaScript

Output

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