I have an array, but I don't know how to remove all of the empty 'subs'
subarrays.
Array
(
[3] => Array
(
[sponsorid] => 2
[user_id] => 3
[subs] => Array
(
[4] => Array
(
[sponsorid] => 3
[user_id] => 4
[subs] => Array
(
[5] => Array
(
[sponsorid] => 4
[user_id] => 5
[subs] => Array
(
[6] => Array
(
[sponsorid] => 5
[user_id] => 6
[subs] => Array()
)
[9] => Array
(
[sponsorid] => 5
[user_id] => 9
[subs] => Array()
)
[10] => Array
(
[sponsorid] => 5
[user_id] => 10
[subs] => Array()
)
)
)
[12] => Array
(
[sponsorid] => 4
[user_id] => 12
[subs] => Array()
)
)
)
[11] => Array
(
[sponsorid] => 3
[user_id] => 11
[subs] => Array()
)
)
)
)
Recursion is necessary as your bottom level subarrays have variable depth.
Code: (Demo)
Output: