remove duplicated array values in a function PHP
Posted
by
Deividas Juškevicius
on Stack Overflow
See other posts from Stack Overflow
or by Deividas Juškevicius
Published on 2012-03-23T11:12:44Z
Indexed on
2012/03/23
11:30 UTC
Read the original article
Hit count: 229
I read all topics related to this question in stackoverflow and whole internet and cant find working sollution... Each owner has his item and when someone buy his item, owner gets an confirmation email, but when in cart is few same owner items, he gets several same email letters, so I need to remove dublicated array entries. I have tried to use DISTINCT and array_uniques functions but no luck. Any advices?
I have an array and function to send mail..
function email($mail_array) {
foreach(array_unique($mail_array) as $field => $value) {
$result = mysql_query("select email from users where $field='$value'");
$row = mysql_fetch_array($result);
$maail = mysql_real_escape_string($row['email']);
$email_to = "".$maail."";
// rest of mail formatting code
// create email headers
$headers = 'From: '.$email_from."\r\n" .
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
}
for ($i = 0; $i < $max; $i++) {
$pid = $_SESSION['cart'][$i]['productid'];
$owner = get_owner($pid);
$mail_array = array(
'name' => $owner
);
email($mail_array) //call function to send mail
}
© Stack Overflow or respective owner