Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP stdClass Object, how to get element with the 0 index [duplicate]

Tags:

php

stdclass

I have a stdClass Object like this:

print_r($myobj);

stdClass Object(
[0] => testData
);

So it is clear that I cannot get the value by $myobj->0.

For getting this value I convert the object to an array, but are there any ways to get without converting?

like image 869
sinitram Avatar asked Dec 28 '15 10:12

sinitram


1 Answers

Try this:

$obj = new stdClass();

$obj->{0} = 1;

echo $obj->{0};

source: http://php.net/manual/en/language.types.object.php

like image 52
narasimharaosp Avatar answered Nov 10 '22 06:11

narasimharaosp