Please help the master to modify a recursive function, so that it has a return value

Source: Internet
Author: User
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;  
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.