天天看點

**PHP錯誤Cannot use object of type stdClass as array in錯誤的

錯誤:将PHP對象類型當做了PHP數組  解決方法:用對象操作符->

今天在PHP輸出一個二維數組的時候,出現了“Fatal error: Cannot use object of type stdClass as array in……”。

這個二維數組是這樣的:

Array ( 

 [0] => stdClass Object ( 

  [id] => 1 

  [title] => 首頁招聘 

  [size] => 297*140 

  [pic] => ./upload/20130302093535.jpg 

  [state] => 0 ) 

 [1] => stdClass Object ( 

  [id] => 2 

  [title] => 首頁領隊 

  [pic] => ./upload/20130302093443.jpg 

 )

輸出開始寫的方法是:$pic[0][title]

結果就出現上面的錯誤。

其實,數組中是傳回的是一個對象,不能直接用[]來顯示,正确的輸出方法是:$pic[0]->title (不用加引号 )

錯誤的:

正确:

如何聯系我:【萬裡虎】www.bravetiger.cn

【QQ】3396726884 (咨詢問題100元起,幫助解決問題500元起)

【部落格】http://www.cnblogs.com/kenshinobiy/