0

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.

  • That code looks reasonable - what's not working? Why not push the addresses directly into PHPMailer instead of putting them in the intermediate array? – Synchro Aug 26 '14 at 14:45
  • Do you just need: `$recipients = array_combine($email, $full_name);`? – Synchro Aug 26 '14 at 14:46
  • Dear Synchro, thank you very much, truly you are a star. that is exactly what I needed. I have a log file that is why I don't want to push the addresses directly into PHPMailer I need the email array for the log file. – user3788645 Aug 26 '14 at 15:11
  • OK, I'll repost that comment as an answer - Please accept it! – Synchro Aug 26 '14 at 15:13

1 Answers1

0

To combine two matching indexed arrays into one associative array (that you can loop over with foreach), you need to use array_combine. For your code that would be:

$recipients = array_combine($email, $full_name);
Synchro
  • 35,538
  • 15
  • 81
  • 104