How can I access the property/ value of an array which has been converted into an object? For instance, I want to access the value in the index 0,
$obj = (object) array('qualitypoint', 'technologies', 'India');
var_dump($obj->0);
error,
Parse error: syntax error, unexpected T_LNUMBER, expecting T_STRING or
T_VARIABLE or ‘{‘ or ‘$’ in C:…converting_to_object.php on line 11
The reason you can not access values via
$obj->0its because it against PHP variable naming see http://php.net/manual/en/language.variables.basics.php for more information. even if you useArrayObjectyou would still have the same issuesbut there is a patch to this … you can convert all integer keys to string or write your own conversion function
Example
Output
Full output
Multi Array Outpur
Thanks
🙂