PHP如何阅读对象的数组? [英] php How to read an array of objects?
本文介绍了PHP如何阅读对象的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在这个问题挣扎了一小时的搜查既计算器和谷歌,但没有找到答案,帮助。我有从的XDebug
如下:
- 列表(阵列) - [0](对象) --- ID(字符串) --- PROJ_NAME(串) --- proj_desc(串)
我试图拔出 ID
的价值。谁能告诉我如何做到这一点?谢谢你。
解决方案
$列表[0] - > ID
-
$列表
是包含在位置的对象数组0
,因此该对象可以用<$访问C $ C> $列表[0] - 对象有一个命名属性
ID
,它可以与$对象 - &GT访问;标识
如果您有数组中的多个对象,那么你可以通过与包含在数组中的值循环 的foreach
。例如:
的foreach($名单$对象){
回声$对象 - &GT; ID。 &LT; BR /&gt;中;
}
这将每个对象数组中,并显示其 ID
值。
Struggling with this problem for an hour now and searched both stackoverflow and google and couldn't find an answer that helped. I have the following from xdebug
:
- list (array)
-[0] (object)
---id (string)
---proj_name (string)
---proj_desc (string)
I am trying to pull out the value of id
. Can anyone tell me how to do this? Thank you.
解决方案
$list[0]->id
$list
is an array containing an object at position0
, therefore this object can be accessed with$list[0]
- the object has a property named
id
, which can be accessed with$object->id
If you have more than one object in the array, then you can loop through the values contained in the array with foreach
. For example:
foreach ($list as $object) {
echo $object->id . "<br/>";
}
This will take each object in the array and display its id
value.
这篇关于PHP如何阅读对象的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文