1

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?

3 Answers 3

1

Try:

$chosenUrls=array();

 for(...)
{
  array_push($chosenUrls,explode ( ',' , $connect[$i]['url'] ));
}
Sign up to request clarification or add additional context in comments.

6 Comments

What do I put in the for loop? Can't figure out why it doesn't work without it though. Shouldn't it just push everything down already there?
array_merge might be a better option than array_push, depending on the desired result.
well in the loop you should iterate your array of ? urls? As you have written -> $connect[$i]['url']= url,url,url
array (size=1) 0 => array (size=2) 0 => string 'http://www.vcricket.com/' (length=24) 1 => string 'http://www.surreycricket.com/' (length=29)
Alex don't think I can do that as that changes on each loop.
|
1

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.

Comments

0

You can have $chosenUrls[] = explode ( ',' , $connect[$i]['url'] ) to add new url in your array in every iteration.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.