【发布时间】:2012-08-22 20:35:39
【问题描述】:
在下面的代码中:
$sth = $dbh->query('SELECT DISTINCT title,courseId,location from training');
$sth->setFetchMode(PDO::FETCH_ASSOC);
$results = $sth->fetchAll();
$uu = array_unique($results);
echo "<pre>";
print_r($uu);
echo "</pre>";
我只从 print_r($uu); 得到 1 个结果
如果我删除 array_unique 将返回所有 (30+) 行。 (不,不是所有的都是重复的):)
我做错了什么?
编辑var_dump() 结果:
array(23) {
[0]=>
array(3) {
["title"]=>
string(26) "String Here"
["courseId"]=>
string(1) "8"
["location"]=>
string(1) "1"
}
[1]=>
array(3) {
["title"]=>
string(26) "Another String Here"
["courseId"]=>
string(1) "8"
["location"]=>
string(1) "2"
}
[2]=>
array(3) {
["title"]=>
string(24) "Third String Here"
["courseId"]=>
string(1) "5"
["location"]=>
string(1) "2"
}
等等……
【问题讨论】:
-
由于隐私问题,我无法显示确切的内容,但我会在一分钟内发布结构......
-
@Paul 展示一个经过消毒的小样本
-
你为什么首先使用
array_unique?DISTINCT不就是这样做的吗? -
我会手动遍历数组并检查是否重复。见stackoverflow.com/questions/4585208/…
-
@Rocket 出于某种原因
DISTINCT没有返回唯一的集合...
标签: php array-unique