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
Share on other sites

$string = 'The start of the string ';
foreach($a as $B)
{
$string .= $b . ' ';
}
$string .= 'the end of the string';

 

Edit: This stupid editor keeps changing $b to $B. Pretend that the $B is a $b.

Edited by haku
Link to comment
Share on other sites

Thanks for the tip. Testing:

 

$string = 'The start of the string ';
foreach($a as $B)
{
$string .= $b . ' ';
}
$string .= 'the end of the string';

 

Edit: turns out the problem isn't the editor, it's the software. Even without the editor, $b becomes $B.

Edited by haku
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.