Ad

Loop Arrays And Merge To A Master Array While Not Knowing Names Of Arrays

I know how to merge arrays manually, but I need to merge arrays in a loop, while not knowing the names of the arrays or how many times they will loop.

I can do this manually:

$masterarray = array_merge_recursive($searchcustomers1, $searchcustomers2);

but how do I do it in a loop. This is what I have:

$pages is how many times it needs to loop

 for ( $i = 1; $i <= $pages; $i += 1) {
        $searchcustomers[$i] = $sc->call.....//an API call
            } 

How would I merge or append all the $searchcustomers[$i] to each other into a master array.

Ad

Answer

Maybe this can help you

$allCustomers = [];
for ($i = 1; $i <= $pages; $i += 1) {
    $allCustomers = array_merge($allCustomers, $searchcustomers[$i]);
}
Ad
source: stackoverflow.com
Ad