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
https://forums.phpfreaks.com/topic/186897-concat-2-loops/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.