Cannot use object of type stdClass as array_PHP教程

來源:互聯網
上載者:User
在我寫php是會出現,如代碼提供錯誤Fatal error: Cannot use object of type stdClass as array

在我寫php是會出現,如代碼提供錯誤

Fatal error: Cannot use object of type stdClass as array

這個問題看提示如果沒有經驗的朋友可能看不出所以然來,下面我們就來看看我這段代碼。

function get_userinfo($id){
$sql ="Select * from @#_debbs where username='$id'";
$result =mysql_query($sql) or die('e');
if( mysql_num_rows($result) ){
$rs = mysql_fetch_object($result);
return array($rs['sex'],$rs['born'],$rs['reg_time'],'/boke/'.$rs['my_photo'],$rs['id']);
}else{
return array('參數錯誤','未知','未知','未知','未知','未知');
}

}

各位看出來是怎麼回事了嗎?

$rs = mysql_fetch_object($result);

看看上面這或,再看看下面

return array($rs['sex'],$rs['born'],$rs['reg_time'],'/boke/'.$rs['my_photo'],$rs['id']);

看出來了沒?我上面是以objcect後下面用的時間又用$rs[]資料訪問形式,當然就會提示出錯哦。

好了問題解決了吧。

http://www.bkjia.com/PHPjc/632471.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/632471.htmlTechArticle在我寫php是會出現,如代碼提供錯誤Fatal error: Cannot use object of type stdClass as array 在我寫php是會出現,如代碼提供錯誤 Fatal error : C...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.