V for Vincent Posted July 19, 2007 Share Posted July 19, 2007 Hi there,I guess this sounds pretty simple, but I can't figure out how to loop through an array and return a string of comma separated values. I'm working on a mailer script that allows you to check a few names and send an e-mail to the right people (given that mailto is useless when your visitors don't use a properly configured client...). The checked boxes produce an array called 'functies', and it is this array which I would like to transform into a string so that I can use it as a header in the mail() function. function recipients() {foreach($_POST['functies'] as $functie) {return "$functie,";}} and $recipients = recipients(); would be the relevant snippets of code here. The 'functies' array contains the checked names. Now, I know that the return statement keeps overwriting previous output, causing mails to arrive in a single person's mailbox. What I don't know is how to solve the issue. I've been trying to concatenate the different 'functie' variables (which is why they have a comma appended to them), but I haven't had much luck so far.Thanks for taking the trouble to look at this. Link to comment Share on other sites More sharing options...
aspnetguy Posted July 19, 2007 Share Posted July 19, 2007 try this function recipients() { $str = ""; $counter = 0; foreach($_POST['functies'] as $functie) { if($counter == 0) $str .= $functie; else $str .= ",{$functie}"; $counter++; }} Link to comment Share on other sites More sharing options...
boen_robot Posted July 19, 2007 Share Posted July 19, 2007 Wouldn't $recipients = implode(',',$_POST['functies']); be sufficient? Link to comment Share on other sites More sharing options...
V for Vincent Posted July 19, 2007 Author Share Posted July 19, 2007 Implode also appears to work.Thanks for both answers, though. I need all the insight I can gather Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.