can i use stdClass like an array?

后端 未结 6 969
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-23 08:21

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

6条回答
  •  情书的邮戳
    2021-01-23 08:48

    I can't really see what you mean to do, short of

    a = array();
    $obj->a[] = 120;
    $obj->a[] = 382;
    // ...
    ?>
    

    You cannot simply "push" a field onto an object. You need to know the name of the field in order to retrieve the value anyways, so it's pretty much nonsense.

提交回复
热议问题