i have this output
i want one function to count all children thanks
im using php version 7.1
Array
(
[0] => stdClass Object
(
[slug] => home
[name] => home
[children] => Array
(
[0] => stdClass Object
(
[slug] => contact-us
[name] => Contact Us
[children] => Array
(
[0] => stdClass Object
(
[slug] => new
[name] => new
[children] => Array
(
[0] => stdClass Object
(
[slug] => km
[name] => km
)
)
)
)
)
)
)
)
i want one function to count all children thanks
im using php version 7.1
3
Answers
Php array count recursive
Be careful your code is has stdClass ,you must that convert to array
A recursive function will give the answer by calling itself each time it detects children:
Working sample at http://sandbox.onlinephpfunctions.com/code/b6769a58b617926ba9daaa1399c4fdda56fab225