Jump to content

concat 2 loops


dreamwest

Recommended Posts

I have 2 foreach loops and need to concat the 2nd loop

 

	
foreach ($c as $a) { //sentences (loops 10 times)

foreach ($d[1] as $e) {//words (loops up to 6 times)

        $cast .= trim($e)."|"; 
}

echo " Cast: {$cast}<br>";

}//end foreach

 

Basically this keep concating the first loop as well

 

eg.

 

1st loop:

Cast: Gary Cooper|Basil Rathbone|

 

2nd loop:

Cast: Gary Cooper|Basil Rathbone|Errol Flynn|Olivia de Havilland|

 

3rd loop:

Cast: Gary Cooper|Basil Rathbone|Errol Flynn|Olivia de Havilland|Nikolai Cherkasov|

 

etc...

 

What it should be is:

 

1st loop:

Cast: Gary Cooper|Basil Rathbone|

 

2nd loop:

Cast: Errol Flynn|Olivia de Havilland|

 

3rd loop:

Cast: Nikolai Cherkasov|

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.