php 如何使用 stdclass 对象从数组中获取值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11240623/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 00:03:36 来源:igfitidea点击:
how to get value from array with stdclass object?
提问by Padam Shankhadev
I have get following output in codeigniter?
我在 codeigniter 中得到了以下输出?
Array
(
[0] => stdClass Object
(
[id] => 8
[book_category] => C Program
[book_id] => 2
[book_name] => C Language
[book_category_id] => 8
[book_in_stock] => 5
)
[1] => stdClass Object
(
[id] => 8
[book_category] => C Program
[book_id] => 1
[book_name] => C++
[book_category_id] => 8
[book_in_stock] => 10
)
[2] => stdClass Object
(
[id] => 9
[book_category] => English
[book_id] => 3
[book_name] => Comp Eng
[book_category_id] => 9
[book_in_stock] => 5
)
[3] => stdClass Object
(
[id] => 9
[book_category] => English
[book_id] => 4
[book_name] => Eng English
[book_category_id] => 9
[book_in_stock] => 5
)
)
so i need get value from the above array without foreach of debugging purpose?
所以我需要在没有调试目的的情况下从上面的数组中获取值?
回答by ariefbayu
Try this:
尝试这个:
echo $array[0]->id;
echo $array[0]->book_category;
回答by young pac
This will get the value easily out
这将很容易获得价值
foreach($array as $key =>$value){
echo $array[$key]->id;
echo $array[$key]->book_category;
}
回答by Aliya
Arrays are never get echoed,Try this with print_r();
数组永远不会得到回显,试试这个 print_r();

