I have a multi-dimensional array (something as below). What am trying to do is find a specific value, and if that value has children, list only those children. So for example, if am searching for slug’s “test”, then all of “test’s” children list on the page. “Test2” has no children, so none listed. If am searching for “/test/sub” (the slug), and since it has children, I wanted to show all of the children (eg. “sh”, “rd”, “co”). Am lost as to how to begin with this, so any help is greatly appreciated.
Array
(
[test] => Array
(
[children] => Array
(
[2] => Array
(
[parent] => 4
[title] => Sub
[slug] => test/sub/
[id] => 2
[children] => Array
(
[3] => Array
(
[parent] => 2
[title] => sh
[slug] => test/sub/sh
[id] => 3
)
[27] => Array
(
[parent] => 2
[title] => RD
[slug] => test/sub/rd
[id] => 27
)
[145] => Array
(
[parent] => 2
[title] => cO
[slug] => test/sub/co
[id] => 145
)
)
)
[8] => Array
(
[parent] => 4
[title] => sub2
[slug] => test/sub2
[id] => 8
)
[19] => Array
(
[parent] => 4
[title] => sub3
[slug] => test/sub3
[id] => 19
[children] => Array
(
[20] => Array
(
[parent] => 19
[title] => child1
[slug] => test/sub3/child1
[id] => 20
)
[21] => Array
(
[parent] => 19
[title] => child2
[slug] => test/sub3/child2 [id] => 21
)
)
)
Ok. I have a way around this, but I am not sure if its the most efficient. Suppose the object that you get after querying the database is $anObject. So we would do,
Basically, I am checking if a particular an object exists for a particular value of $i and then see if it has a value for a particular value of $j. You could change these values if you know the range of the integers. When we get it we grab it in a $slug variable, and then you add some procedure in that part to use this value.
Let me know if this was of any help.