can i use stdClass like an array?

后端 未结 6 898
爱一瞬间的悲伤
爱一瞬间的悲伤 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:45

    In short, no, because you will always have to name your properties. Going through the trouble of writing a simple class with ArrayAccess makes no sense either as you've essentially recreated an array with nothing to show for it except extreme sacrifices in performance and transparency.

    Is there some reason your problem cannot be solved infinitely more simply by using an array, or is this just a wish-I-knew question?

    EDIT: Check out this question for more info.

提交回复
热议问题