簡體   English   中英

foreach數組錯誤

[英]foreach array error

我編碼了

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

這是給出結果的

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

但是當我調用print_r($row[follow_date]); ,給出錯誤

致命錯誤:不能在第34行的/homereports/bespoke_dialing_status.php中使用stdClass類型的對象作為數組

有人能說出問題是什么嗎?

使用: $row->follow_date訪問內容。

答案是在錯誤中,您正在嘗試將stdClass用作數組,這是不可能的。

由於$rowstdClass,因此您需要使用另一種語法來檢索日期。

$date = $row->follow_date;

那會給你想要的結果。

我沒有辦法檢查但我記得在類似的問題上使用類似$row->follow_date

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM