Please help the master to modify the recursive function, so that it has a return value
At the moment I have a recursive function that echoes out the ID value in a multi-dimensional array
Echo to page appears as "1,2,3,4,5 ..."
PHP Code
function Arr_fun ($arr) { if (Is_array ($arr)) { foreach ($arr as $v) { if (Is_array ($v)) { arr_fun ($v); } else{ echo $arr [id]. ","; Break;}}} else{ Echo $arr. ","; }
Because I need to use this string of ID strings from ECHO.
Attempt to assign value to $s unsuccessful $s =arr_fun ($array _menu); Note: $array _menu is a dynamic multidimensional array whose dimensions are dynamically changing
So I think the above method has no return value, so it can't be assigned
Hope that the elder enlighten, help me revise, how can let its return value also "1,2,3,4 ..."?
------Solution--------------------
PHP Code
function Arr_fun ($arr) { $r = '; if (Is_array ($arr)) { foreach ($arr as $v) { if (Is_array ($v)) { $r. = Arr_fun ($v); } else{ $r. = $arr [id]. ","; Break;}}} else{ $r. = $arr. ","; } return $r;