Собирает все подмассивы и строки массива в единый массив

Код

$collect_array = [];
function collect_array($array){
    global $collect_array;
    if(is_array($array)){
        foreach ($array as $key => $value) {
            if(is_array($value)){
                $collect_array = collect_array($value); 
            }
            else {                
                $collect_array[] = $value;
            }
        }
    }
    else {
        $collect_array[] = $array;
    }
    return $collect_array;
}

Пример

$array2 = array(
    array(1, 3, 4, 5, 6), 
    array(5,4,5,6,7,2));

$collect_array = [];
$collect_array = collect_array(array2);