在不知道数组名称的情况下循环数组并合并到主数组

Loop arrays and merge to a master array while not knowing names of arrays

我知道如何手动合并数组,但我需要在循环中合并数组,同时不知道数组的名称或它们将循环多少次。

我可以手动执行此操作:

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

但是我如何在循环中执行此操作。这是我的:

$pages是需要循环多少次

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

我如何将所有 $searchcustomers[$i] 合并或附加到主数组中。

也许这可以帮到你

$allCustomers = [];
for ($i = 1; $i <= $pages; $i += 1) {
    $allCustomers = array_merge($allCustomers, $searchcustomers[$i]);
}