0
$data = "email@yahoo.com,go@gmail.com,example@example.com";
list($email1, $email2, $email3) = explode(",", $data);
echo $email1; // email@yahoo.com
echo $email2; // go@gmail.com

Pretty perfect but my problem is I don't know how many email addresses will be inserted by a user. He can input just 1/2 or even 30/40.

So the style of below won't work.

echo $email1; 
echo $email2;

I must use loop or something right? yes, just guide me how you will use loops to handle this kinda situation?
Again, 1)User can insert many emails and
2) I have to retrieve every email address as separate string.

Thanks in advance!

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by TechySafi
0

Hi TechySafi,

For this kind of situation, sure you can approach via looping. By exploding every value stored in an array, using foreach you can get the values.

$data = "email@yahoo.com,go@gmail.com,example@example.com";
$emails = explode(",", $data);
foreach($emails as $email) {
	echo $email." ";
}
0

Something like this will work.
skip the list() function and loop with foreach..

$data = "email@yahoo.com,go@gmail.com,example@example.com";
$emails = explode(",", $data);

foreach($email in $emails)
{
	echo $email
}

Foreach don't like empty arrays so some additional checkups is needed.

0

Thanks both of you. I got it :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.