dreamwest Posted January 2, 2010 Share Posted January 2, 2010 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 More sharing options...
trq Posted January 2, 2010 Share Posted January 2, 2010 foreach ($c as $a) { $cast = ''; foreach ($d[1] as $e) { $cast .= trim($e)."|"; } echo " Cast: {$cast}<br>"; } Link to comment https://forums.phpfreaks.com/topic/186897-concat-2-loops/#findComment-986990 Share on other sites More sharing options...
dreamwest Posted January 2, 2010 Author Share Posted January 2, 2010 Sweet! Thanks Link to comment https://forums.phpfreaks.com/topic/186897-concat-2-loops/#findComment-987008 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.