Jump to content

foreach inside of a string


searls03

Recommended Posts

Currently I am working on an email script. I need to be able to use a foreach inside of the message. something like this:

$message = '<table width="0" border="0" cellspacing="2" cellpadding="2">
 <tr>
   <td>Registrant</td>
   <td>Event</td>
   <td>Date</td>
   <td>Time</td>
   <td>Participants</td>
   <td> </td>
 </tr>
 <tr>
   <td>'.$name.'</td>
   <td>'.$event.'</td>
   <td>'.$date.'</td>
   <td>'.$time.'</td>
   <td>'.foreach($_POST["participant"] AS $key => $val) {
$participant = $val;
echo $participant;
}.'</td>
   <td> </td>
 </tr>
</table>';

 

I know this isnot the proper way to do it, so I was wondering, what is the proper way to do this, or what is the best way to achieve this result? any help is greatly appreciated

Link to comment
https://forums.phpfreaks.com/topic/272785-foreach-inside-of-a-string/
Share on other sites

foreach($a as $B)

 

Edit: That does indeed do it. Thanks. But what a pain in the butt - particularly since it doesn't even render it as a smiley!

 

It probably doesn't allow smilies inside code blocks. But it is weird that it still parses the syntax regardless.

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.