我知道如何手动合并数组,但我需要在循环中合并数组,同时不知道数组的名称或它们将循环多少次。
我可以手动执行此操作:
$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]);
}