Php 条令-查询返回嵌套数组,而不是一个
我正在做这个查询Php 条令-查询返回嵌套数组,而不是一个,php,sql,symfony,doctrine-orm,dql,Php,Sql,Symfony,Doctrine Orm,Dql,我正在做这个查询 public function getRecommendedVendors($user) { $q = $this->em->createQuery( " select cat.id from Zgh\FEBundle\Entity\Category cat inner join cat.users u where u = :user "
public function getRecommendedVendors($user)
{
$q = $this->em->createQuery(
"
select cat.id
from Zgh\FEBundle\Entity\Category cat
inner join cat.users u
where u = :user
"
);
$q->setParameters(["user" => $user]);
var_dump($q->execute());
die;
return $q->execute();
}
执行var_转储返回:
我希望它返回的位置,因为我在IN语句中使用了结果:
array (size=2)
0 =>
'id' => string '1' (length=1)
1 =>
'id' => string '10' (length=2)
您体验的是默认的查询行为:第一个数组“level”是行,第二个“level”是列。当然,您只有一列,因此它看起来有点奇怪 您应该使用getScalarResult而不是execute。要了解更多信息,请阅读尝试这样转储$tmp=$q->execute;var_dump$tmp[0];而不是整件事。干杯
array (size=2)
0 =>
'id' => string '1' (length=1)
1 =>
'id' => string '10' (length=2)