Reputation: 1648
I have this statement inside a loop.
$chosenUrls = explode ( ',' , $connect[$i]['url'] );
Is there anyway to get it to add to the $chosenUrls array, rather than replacing what's in there?
Upvotes: 1
Views: 1756
Reputation: 1979
Your current code tells it to replace $chosenUrls
every time. You need to modify it:
for(...){
$chosenUrls[] = explode ( ',' , $connect[$i]['url'] );
}
Note the []
after $chosenUrls
. This will push a new element into $chosenUrls
on each iteration.
Upvotes: 1
Reputation: 801
You can have $chosenUrls[] = explode ( ',' , $connect[$i]['url'] ) to add new url in your array in every iteration.
Upvotes: 0
Reputation: 161
Try:
$chosenUrls=array();
for(...)
{
array_push($chosenUrls,explode ( ',' , $connect[$i]['url'] ));
}
Upvotes: 1