Possible duplicate:Traversing an array with numeric keys as an object
I did a casting from array to object, and I'm confused:
$arr = range(1,3); $obj = (object) $arr; var_dump($obj) object(stdClass)#2 (5) { [0]=> int(1) [1]=> int(2) [2]=> int(3) }
The question arises: how to access the attributes of an object in this case? $obj->0 causes a syntax error.
$obj->0
You cannot access these properties of the object unless you return to the array. Period. If you need to do this for some reason, set the array keys to something else.
In this case, the only thing I can think of is to access the properties using foreach as follows:
foreach
foreach($obj as $key => $value) var_dump("$key => $value");
but of course, this will not solve the main problem.
It looks like the ArrayObject class can access properties
$a = new ArrayObject($obj); echo $a[0];
Source: https://habr.com/ru/post/913656/More articles:Is there a way to save the state of a Netbeans group / tab? - netbeansGetting resources with php and MWS - phpUsing ActionBarSherlock & ViewPagerIndicator will not compile synchronously - androidIs there any existing Java library that allows you to quickly, in memory, search for zipcodes (bonus, state and city) from latitude / longitude? - javaHow to get a control location relative to its shape location? - c #OS X editor (or IDE) that is really good for developing node.js "? - javascriptInsert INTO MySQL from another table - mysqlDebugging and Write / WriteLine tracing are not output in Visual Studio 2010 C # Express - c #Lock static class elements - javaWindows Phone - XmlDocument Not Found - c #All Articles