简体   繁体   English

foreach数组错误

[英]foreach array error

I have coded 我编码了

foreach($DB->query($query) as $row){
print_r($row);

which is giving result as 这是给出结果的

 stdClass Object ( [follow_date] => 2012-04-17 [status] => 1 [user_id] => 8 ) stdClass Object ( [follow_date] => 2012-04-17 [status] => 2 [user_id] => 9 ) 

but when i am calling print_r($row[follow_date]); 但是当我调用print_r($row[follow_date]); , its giving error ,给出错误

Fatal error: Cannot use object of type stdClass as array in /homereports/bespoke_dialing_status.php on line 34 致命错误:不能在第34行的/homereports/bespoke_dialing_status.php中使用stdClass类型的对象作为数组

Can somebody tell what's the problem? 有人能说出问题是什么吗?

使用: $row->follow_date访问内容。

The answer is in the error, you are trying to use stdClass as an array, which is not possible. 答案是在错误中,您正在尝试将stdClass用作数组,这是不可能的。

Since $row is a stdClass you need to use another syntax to retrieve the date. 由于$rowstdClass,因此您需要使用另一种语法来检索日期。

$date = $row->follow_date;

That should give you the result you want. 那会给你想要的结果。

我没有办法检查但我记得在类似的问题上使用类似$row->follow_date

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM