I have a multi dimensional array that contains a hierarchy of a navigation. I want to search for the name
key for a specific element. There can be x amounts of levels in the hierarchy.
I want to search in the multi dimensional array and return a filtered multi dimensional array (with the same structure), only with the searched values. I have looked at different solutions, but they only seems to return the value.
Any help is appreciated.
This is my array now:
Array
(
...
[60] => Array
(
[term_id] => 60
[name] => Vinylbiler
[slug] => vinylbiler
[term_group] => 0
[term_taxonomy_id] => 60
[taxonomy] => toys
[description] =>
[parent] => 0
[count] => 2
[filter] => raw
[children] => Array
(
[63] => Array
(
[term_id] => 63
[name] => 1:43 serien
[slug] => 143-serien
[term_group] => 0
[term_taxonomy_id] => 63
[taxonomy] => toys
[description] =>
[parent] => 60
[count] => 2
[filter] => raw
[children] => Array
(
[64] => Array
(
[term_id] => 64
[name] => Gul
[slug] => gul
[term_group] => 0
[term_taxonomy_id] => 64
[taxonomy] => toys
[description] =>
[parent] => 63
[count] => 1
[filter] => raw
[children] => Array
(
)
)
[65] => Array
(
[term_id] => 65
[name] => Rød
[slug] => rod
[term_group] => 0
[term_taxonomy_id] => 65
[taxonomy] => toys
[description] =>
[parent] => 63
[count] => 1
[filter] => raw
[children] => Array
(
)
)
)
)
)
)
)
If I search for "Gul" I want to have an array looking like this:
[60] => Array
(
[term_id] => 60
[name] => Vinylbiler
[slug] => vinylbiler
[term_group] => 0
[term_taxonomy_id] => 60
[taxonomy] => toys
[description] =>
[parent] => 0
[count] => 2
[filter] => raw
[children] => Array
(
[63] => Array
(
[term_id] => 63
[name] => 1:43 serien
[slug] => 143-serien
[term_group] => 0
[term_taxonomy_id] => 63
[taxonomy] => toys
[description] =>
[parent] => 60
[count] => 2
[filter] => raw
[children] => Array
(
[64] => Array
(
[term_id] => 64
[name] => Gul
[slug] => gul
[term_group] => 0
[term_taxonomy_id] => 64
[taxonomy] => toys
[description] =>
[parent] => 63
[count] => 1
[filter] => raw
[children] => Array
(
)
)
)
)
)
)
And If I search for "Vinylbiler" I want an array looking like this:
[60] => Array
(
[term_id] => 60
[name] => Vinylbiler
[slug] => vinylbiler
[term_group] => 0
[term_taxonomy_id] => 60
[taxonomy] => toys
[description] =>
[parent] => 0
[count] => 2
[filter] => raw
[children] => Array
(
)
)
Edit:
I know that my question is vague and doesn't show any code attempts. I have tried different variations of array_search
without luck.
http://php.net/manual/en/function.array-search.php
Any help, links or pinpoints to where I can find help to this problem is highly appreciated.