array_unique只返回一条记录

Pau*_*ert 2 php array-unique

在下面的代码中:

$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>";
Run Code Online (Sandbox Code Playgroud)

我只得到1个结果 print_r($uu);

如果我删除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"
  }
Run Code Online (Sandbox Code Playgroud)

等等...

Dav*_*ker 5

从我array_unique对它的理解不会递归迭代数组.因此,它将看到除了一个值之外的$uu === array()所有值,同时保留密钥.如果键总是为0,我不会感到惊讶.

在手册中查看说明:

请注意,array_unique()不适用于多维数组.