So firstly, even though it appears from print_r()
's output that the property is literally integer 0
, it is not. If you call var_dump()
on the object instead, you'll see that, in fact, it looks like this:
php > var_dump($myobject);
object(stdClass)#2 (1) {
["0"]=>
string(4) "testData"
}
So how do you access a property named 0
when PHP won't let you access $myobject->0
? Use the special Complex (curly) syntax:
php > echo $myobject->{0};
test
php > echo $myobject->{'0'};
test
php >
You can use this method to access property names that are not considered valid syntax.
echo $myobj->{0};
– Tonne