I am using Doctrine (DQL) with ZF2 to perform the following query:
我正在使用带有ZF2的Doctrine(DQL)来执行以下查询:
$qb->select('a.schoolID, a.schoolName')
->from('College\Entity\School', 'a');
$schools=$qb->getQuery()->getResult();
This returns and array of objects or a two dimensial Array as such:
这将返回对象数组或二维数组,如下所示:
array (size=2)
0 =>
array (size=2)
'schoolID' => int 1
'schoolName' => string 'Alabama A & M University' (length=24)
1 =>
array (size=2)
'schoolID' => int 2
'schoolName' => string 'University of Alabama at Birmingham'
My question is: How and What's the best approach to access an Array of this type with unknown numbers of objects in it.
我的问题是:如何以及什么是访问此类型数组的最佳方法,其中包含未知数量的对象。
1 个解决方案
#1
2
What do you mean? It's a plain array.
你什么意思?这是一个简单的阵列。
You can, for example, loop through it like:
例如,您可以循环遍历它:
foreach ($schools as $school)
{
// Do something with $school, like:
echo $school['schoolName'];
}
You can query the number of items like count($schools)
.
您可以查询计数($学校)等项目的数量。
#1
2
What do you mean? It's a plain array.
你什么意思?这是一个简单的阵列。
You can, for example, loop through it like:
例如,您可以循环遍历它:
foreach ($schools as $school)
{
// Do something with $school, like:
echo $school['schoolName'];
}
You can query the number of items like count($schools)
.
您可以查询计数($学校)等项目的数量。