0
function array_flatten($array,$return) {
    for($x = 0; $x <= count($array); $x++) {
        if(is_array($array[$x])) {
            $return = array_flatten($array[$x], $return); //4th line
        }
        else {
            if(isset($array[$x])) {
                 $return[] = $array[$x];
            }
        }
    }
    return $return;
}

$res = array_flatten($myarray, array());

I used the above function to flatten my nested, but am still struggling to figure out why do the author passed the function back to $return on line 4. and if I were to change $return on line 4 to something else, the function breaks. Can anyone explain..

Nigel Ren
  • 56,122
  • 11
  • 43
  • 55
Salam.MSaif
  • 209
  • 3
  • 10

0 Answers0