How to traverse an infinite array with a return

Source: Internet
Author: User
How do I iterate through an infinite array with a return?
$arr =array (Array (6,66), 8);
function Arr_p ($arr) {
foreach ($arr as $v) {
if (Is_array ($v)) {
Arr_p ($v);
}else{
echo $v. "
";}
}
}
Arr_p ($arr);
?>

This paragraph is the direct echo out, now want to use return, do not know how to start, I hope the expert pointing! (younger brother is PHP beginner)

------Solution--------------------
$arr =array (Array (6,66), 8);
function Arr_p ($arr) {
$r = ";
foreach ($arr as $v) {
if (Is_array ($v)) {
$r. = Arr_p ($v);
}else{
$r. = $v. "
";}
}
return $r;
}
echo arr_p ($arr);
------Solution--------------------
PHP Code
function Arr_p ($arr) {  $r = ';//Because you want to return data, there is a carrier  foreach ($arr as $v) {    if (Is_array ($v)) {///If it is an array, it is recursively entered      $r. = Arr_p ($v);//Catch the returned data    } else{      $r. = $v. "
"; Not an array, do you want to save the data?} return $r;//Return Data}
  • 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.