Question

I have created a function that loops through another function, and the other function returns an array. If I loop through the other function four times, I will get four arrays returned but only one per loop. I would like to merge these four arrays into one array inside my new function.

This is the new function:

function groups() {
    $b = array();
    $r = 65;
    while ($r <= 69) {
        $b = bookings($r);
        $merge = array_merge($b);
        $r++;
    }
    return $merge;
} 

This function only returns the bookings for group 69, but I want to get the bookings for 65, 66, 67, 68 and 69. Please help! Sorry if something is confusing.

Was it helpful?

Solution

function groups() {
    $merge = array();
    $r = 65;
    while ($r <= 69) {
        $b = bookings($r);
        $merge = array_merge($merge, $b);
        $r++;
    }
    return $merge;
} 

OTHER TIPS

You may try array_push() function

$b = array_push($b, $r);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top