I think the other answers here are misunderstanding your question.
fetchLinks()
returns an array as its result. If you were to simply add this result to the existing $link_repository
variable, that variable would end up as a multidimensional array - i.e. an array of arrays. For example, if the first call to fetchLinks()
returned array(1,2)
and the second call returned array(3,4)
, this would give you a $link_repository
variable that looks like array(array(1,2), array(3,4)
.
What I think you're actually asking for is a way to make it so that the results of all calls to fetchLinks()
combine to form a one-dimensional array. In the above example, you would want the final result of $link_repository
to be array(1,2,3,4)
.
If this is correct, then what you want to do is merge the arrays together with array_merge
:
$link_repository=array();
foreach ($links as $value) {
$link_repository= array_merge($link_repository, $crawler->fetchLinks($value));
}
I'm not sure about the performance tradeoffs, but you may want to defer the array_merge
until the end. If you add each fetchLinks
array as its own element in $link_repository
, then you can merge them all at once by passing every element in the array to array_merge
at once by using user_call_func_array()
.
It's worth noting that you may want to use the array union operator, +
, to merge the arrays, depending on what sort of data fetchLinks
returns. See here for discussion on how that operator works, and see here for a discussion on how it differs from array_merge
.