How to access stdclass object after a specific key value pair?
there are serveral ways to turn it to array:
First Solution:
$value = get_object_vars($object);
Second Solution:
$value = (array) $object;
Third Solution
$value = json_decode(json_encode($object), true);
to get value of converted array
echo $value['values']['0']['id'];
The alternate way to access objects var without convert the object, try
$object->values->{'0'}->id
I had the same issue, still not so sure why but I was able to get it working using this workaround:
$k2 ="1";$elements = json_decode('{"id":"1","name":"User1"}');//$elements['id'] == $k2; //****Not Working$tmp = (object)$elements;$tmp = $tmp ->id; //****Working//$tmp =$elements['id'] ; //****Not Workingreturn $tmp == $k2;
I have to say that sometimes accessing the element as array works and some times not,(On PHP7 it worked for me but on PHP5.6 it didn't).
$elements
can be Array to but I chose to demonstrate with json string.
I hope this helps somehow !!!