PHP Arrays - Trying to get property of non-object

前端 未结 3 765
逝去的感伤
逝去的感伤 2021-02-09 13:31

I am still new to PHP so please bear with me.

So I am getting this error: Notice: Trying to get property of non-object on this line:

echo (
            \         


        
3条回答
  •  不思量自难忘°
    2021-02-09 13:35

    As you are working with an array, you should use [] to access the array's items :

    echo $row['last_name'];
    

    Use the right syntax, and the error will go away ;-)


    Still, if you really want to convert an array to an object (not really sure why you'd do that, though, in this specific case), you can use this :

    $row = (object)$row;
    echo $row->last_name;
    

    Here's the relevant section of the manual : Type Casting

提交回复
热议问题