is it possible to make stdClass objects work like a generically indexed array?
i.e. $array = Array ( [0] => 120 [1] => 382 [2] => 552 [3] => 595 [4] => 616 )
wou
No, you can't. Using the brackets ([]
) like that is called "ArrayAccess" in PHP, and is not implemented on the stdClass
object.
It sounds like you might want something like
$foo = new stdClass();
$foo->items = array();
$foo->items[] = 'abc';
$foo->items[] = '123';
$foo->items[] = 'you and me';
You could also try casting an array as a stdClass to see what happens.
$foo = array();
$foo[] = 'abc';
$foo[] = '123';
$foo[] = 'you and me';
$foo = (object) $foo;
var_dump($foo);