Member Avatar for TechySafi
$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!

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." ";
}

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.

Member Avatar for TechySafi

Thanks both of you. I got it :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.