简体   繁体   中英

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]); , its giving error

Fatal error: Cannot use object of type stdClass as array in /homereports/bespoke_dialing_status.php on line 34

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.

Since $row is a stdClass you need to use another syntax to retrieve the date.

$date = $row->follow_date;

That should give you the result you want.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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