Home  >  Article  >  Backend Development  >  Cannot use object of type stdClass as array_PHP教程

Cannot use object of type stdClass as array_PHP教程

WBOY
WBOYOriginal
2016-07-13 10:52:32908browse

When I write php, an error will appear, as shown in the code below. Fatal error: Cannot use object of type stdClass as array

When I write php, an error will appear, as shown in the code below

Fatal error: Cannot use object of type stdClass as array

If you have no experience with this question, you may not understand why. Let’s take a look at my code below.

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('parameter error','unknown','unknown','unknown','unknown','unknown');
}
 
}

Do you see what’s going on?

$rs = mysql_fetch_object($result);

Look at this or below, and then look at this below

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

Did you see it? I used the $rs[] data access format for the time used above after objcect and the time used below. Of course, an error will be prompted.

Okay, the problem is solved.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632471.htmlTechArticleWhen I write php, it will appear, as shown in the code below. Fatal error: Cannot use object of type stdClass as array When I write php, there will be an error, as shown in the code below. Fatal error: C...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn