Foreach源PHP数组和对象 [英] PHP Foreach Arrays and objects
本文介绍了Foreach源PHP数组和对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有对象的数组。
一的print_r看起来像这样
I have an array of objects. A print_r looks like this
Array
(
[0] => stdClass Object
(
[sm_id] => 1
[c_id] => 1
)
[1] => stdClass Object
(
[sm_id] => 1
[c_id] => 2
)
)
我真的在努力寻找一种方法,虽然循环的结果,并访问对象的元素。
如果任何人都可以给我任何指针,我将非常感激。
I am really struggling to find a way to loop though the results and access the object elements. If anyone could give me any pointers i would be extremely grateful.
在此先感谢
推荐答案
使用
//$arr should be array as you mentioned as below
foreach($arr as $key=>$value){
echo $value->sm_id;
}
或
//$arr should be array as you mentioned as below
foreach($arr as $value){
echo $value->sm_id;
}
这篇关于Foreach源PHP数组和对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文