How do I declare a two dimensional array?

前端 未结 14 1527
爱一瞬间的悲伤
爱一瞬间的悲伤 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 22:11

    Or for larger arrays, all with the same value:

    $m_by_n_array = array_fill(0, $n, array_fill(0, $m, $value);
    

    will create an $m by $n array with everything set to $value.

    0 讨论(0)
  • 2020-11-29 22:14

    And I like this way:

    $cars = array
      (
      array("Volvo",22),
      array("BMW",15),
      array("Saab",5),
      array("Land Rover",17)
      );
    
    0 讨论(0)
提交回复
热议问题