How do I declare a two dimensional array?

前端 未结 14 1564
爱一瞬间的悲伤
爱一瞬间的悲伤 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条回答
  •  -上瘾入骨i
    2020-11-29 22:03

    Just declare? You don't have to. Just make sure variable exists:

    $d = array();
    

    Arrays are resized dynamically, and attempt to write anything to non-exsistant element creates it (and creates entire array if needed)

    $d[1][2] = 3;
    

    This is valid for any number of dimensions without prior declarations.

提交回复
热议问题