I find it peculiar converting an indexed array to an object. Consider the following:
$arr = array('John', 'Jenny');
$obj = (object) $arr;
echo $obj->{0}; // Notice: Undefined property: stdClass::$0
The goal here is to be able to simply tap into and echo out the value 'John' via $obj while making use of stdClass. Since arrays being converted to objects assign array keys to object properties while the array values become those properties' values, this means that the property 0 will have the value 'John' while the property 1 will have 'Jenny'.
Simply using print_r in place of that last line in the snippet demonstrates this:
echo '<pre>'.print_r($obj, true);
//Output:
stdClass Object
(
[0] => John
[1] => Jenny
)
According to this comment from the manual, these properties cannot be accessed (due to variable naming convention violations - as we know that you cannot start a variable name with a number; therefore I am confused by this allowance in cases like this).
So, in light of all this, I find one way of doing things as such:
$arr = array('John', 'Jenny');
$obj = (object) $arr;
foreach($arr as $val){
$obj->index[] = $val;
}
echo $obj->index[0]; // echo out an individual index of choice
However, I am wondering of there is a way of actually tapping into properties that are given numbers as names without the need to looping shenanigans like foreach...