How to merge or join or map two arrays fetched from mysql db array full_name and array email to create one recipient list to be bcc for php mailer and then be able to use something like:

$email= array();
$full_name= array();



while loop starts
array_push($email, $row['email']);
array_push($full_name, $row['full_name']);
loop ends

At the end of the while loop i want to merge or join two arrays as shown above how can I do that? can anybody kindly guide me in the right direction?

foreach($recipients as $email => $full_name)
{
   $mail->AddBCC($email, $full_name);
}

Many thanks for your valuable help and advice.

Recommended Answers

All 2 Replies

Why don't you push both values (the entire record) to the same array:

while () {
    $recipients[] = $row;
}

foreach ($recipients as $recipient) {
    $mail->AddBCC($recipient['email'], $recipient['full_name']);
}

Thank you very much pritaeas, your solution works as well as array combine.

$recipients = array_combine($email, $full_name);

foreach($recipients as $email => $full_name)
{
    $mail->AddBCC($email, $full_name);
}
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.