数组中列的 PHP 唯一值 [英] PHP Unique Values from Column in Array
本文介绍了数组中列的 PHP 唯一值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个从我运行的 SQL 查询生成的数组.如下所示:
I have an array that is generated from a SQL query that I run. It looks like the following:
$arr[$i]['id'] = $id;
$arr[$i]['name'] = $name;
$arr[$i]['email'] = $email;
如何从电子邮件列中获取唯一值?感谢您的帮助.
How can I get the unique values from the email column? I appreciate the help.
推荐答案
要么使用 MySQL 中的 DISTINCT 方法在您的列中过滤它,要么使用类似的东西
Either filter it in your column using the DISTINCT method in MySQL, or use something like
$uniqueEmails = array();
foreach($arr as $array)
{
if(!in_array($array['email'], $uniqueEmails)
$uniqueEmails[] = $array['email'];
}
这篇关于数组中列的 PHP 唯一值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文