How do I declare a two dimensional array?

前端 未结 14 1573
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-29 21:46

What\'s the easiest way to create a 2d array. I was hoping to be able to do something similar to this:

declare int d[0..m, 0..n]
14条回答
  •  再見小時候
    2020-11-29 21:52

    You can try this, but second dimension values will be equals to indexes:

    $array = array_fill_keys(range(0,5), range(0,5));

    a little more complicated for empty array:

    $array = array_fill_keys(range(0, 5), array_fill_keys(range(0, 5), null));

提交回复
热议问题