Php 初始化数组的数组

Php 初始化数组的数组,php,Php,我想知道是否有比下面更简单的方法来做同样的事情,但代码更少 private $table = array( array(array(), array(), array(), array(), array()), array(array(), array(), array(), array(), array()), array(array(), array(), array(), array(), array()),

我想知道是否有比下面更简单的方法来做同样的事情,但代码更少

    private $table = array(
        array(array(), array(), array(), array(), array()),
        array(array(), array(), array(), array(), array()),
        array(array(), array(), array(), array(), array()),
                               ...
        array(array(), array(), array(), array(), array())
    );
<> P>我知道C++是可行的,但不确定PHP中是否有类似的东西。
提前感谢您的帮助。

如果这是一个已知大小的直矩形,您可以使用嵌套循环:

$table = array();
for ($row = 0; $row < $rowCount; $row++)
{
  $thisRow = array ();
  for ($col = 0; $col < $colCount; $col++)
  {
    $thisRow[] = array ();
  }
  $table[] = $thisRow;
}
$table=array();
对于($row=0;$row<$rowCount;$row++)
{
$thisRow=array();
对于($col=0;$col<$colCount;$col++)
{
$thisRow[]=array();
}
$table[]=$thisRow;
}

我知道这不完全是您要求的,但至少它比您当前的设置更能抵抗更改(如添加列)。

如果这是一个已知大小的直矩形,您可以使用嵌套循环:

$table = array();
for ($row = 0; $row < $rowCount; $row++)
{
  $thisRow = array ();
  for ($col = 0; $col < $colCount; $col++)
  {
    $thisRow[] = array ();
  }
  $table[] = $thisRow;
}
$table=array();
对于($row=0;$row<$rowCount;$row++)
{
$thisRow=array();
对于($col=0;$col<$colCount;$col++)
{
$thisRow[]=array();
}
$table[]=$thisRow;
}
我知道这不完全是你要求的,但至少它比你当前的设置更能抵抗更改(比如添加列)。

你可以使用

你可以用


这里也是,我很高兴我问了;)这里也是,我很高兴我问了;)谢谢,我感谢你的帮助,但正如你所说,这不是我想要的(我实际上在每个索引中都避开了循环和“特定”的任务…)谢谢,我感谢你的帮助,但正如你所说,这不是我想要的(我实际上在每个索引中都避开了循环和“特定”的任务…)