$email_users[] = $row;
print_r($email_users);
结果:
Array (
[0] => Array (
[user_id] => 87436
[username] => Admin
[user_email] => email@online.us
[user_lang] => de
[allowed] => 1 )
[1] => Array (
[user_id] => 68013
[username] => Testuser
[user_email] => email2@online.us
[user_lang] => de
[allowed] => 1 )
[2] => Array (
[user_id] => 68013
[username] => Testuser
[user_email] => email2@online.us
[user_lang] => de
[allowed] => 1 )
)
如您所见,user_id 68013是双倍的。我必须删除双数组。结果应如下所示:
Array (
[0] => Array (
[user_id] => 87436
[username] => Admin
[user_email] => email@online.us
[user_lang] => de
[allowed] => 1 )
[1] => Array (
[user_id] => 68013
[username] => Testuser
[user_email] => email2@online.us
[user_lang] => de
[allowed] => 1 )
)
我阅读并尝试了在堆栈上找到的几种解决方案。例如:
如何在多维数组中获取唯一值
$email_users[] = $row;
$user_ids = array();
foreach ($email_users as $h) {
$user_ids[] = $h['user_id'];
}
$email_users = array_unique($user_ids);
print_r($email_users);
但print_r只是:
Array ( [0] => 87436 [1] => 68013 )
谢谢你的时间。
您应该从查询中获得不同的值。使用从表名中选择不同的 *,您将获得非重复值。或者使用 $email_users= array_unique($email_users, SORT_REGULAR(;