You can pass an object to an array as follows:
$myarray = (array)$myobject;
And then for an array that has only one value, this should extract the key for that value.
$value = key($myarray);
You can do this on one line if you want. Of course, you can also do this by listing the object, as you mentioned in your question.
To get a value, not a key, follow these steps:
$value = current($myarray);
thomasrutter
source share