foreach into 1 variable

3 posts by 2 authors in: Forums > CMS Builder
Last Post: November 7, 2013   (RSS)

By zaba - November 6, 2013

Hi, I have a foreach loop of email addresses that I need to combine into 1 variable for use later in my script, each email needs a coma separating it (but not at the end)

    <?php foreach ($notifyRecords as $record): ?>
      <?php echo $record['notify_email'] ?> ,
    <?php endforeach ?>

So I want the resulting variable to be something like this built from the foreach statement above:

$recipients='bob@margaret.com, margaret@brian.com, maureen@bob.com, sid@margaret.com';

By zaba - November 7, 2013

Hey Brownleather,

your solution works perfectly, thank you for taking the time to post. Much appreciated. All the best Chris.