php - Can't access stdObject array using [] or -> operators -
this question has answer here:
- how can access array/object? 4 answers
i have stdobject
, var_dump
result below:
var_dump($name) array(1) { [0]=> object(stdclass)#853 (2) { ["firstname"]=> string(2) "john" ["lastname"]=> string(8) "smith" } }
i trying make new variable $fullname
using $name['firstname].$name['lastname']
. doesn't work, gives error undefined index
then tried using ->
operator on $name->firstname + $name->lastname
. gives error: trying property of non-object
how go this?
$name[0]->firstname . $name[0]->lastname;
basically trying access array object. can see var_dump
variable contains array. array contains object 2 properties. $name[0]
gives object, , ->firstname
accesses firstname
property of object.
Comments
Post a Comment