在PHP中创建一个空的2D数组? [英] Creating an empty 2D array in PHP?
本文介绍了在PHP中创建一个空的2D数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
($ j)
{
($ i)
{
$ array [j] [i] =data;
}
}
这样的东西?
解决方案
在其绝对最简单的情况下,2D维数组可以创建为:
<?php
$ emptyArray = array(array());
?>
或者从PHP 5.4开始,您还可以使用:
<?php
$ emptyArray = [[]];
?>
I know that arrays are created dynamically, and creating them ahead of time isn't really necessary, but how would one do that with a 2D array? The same way?
(for$j)
{
for($i)
{
$array[j][i] = "data";
}
}
Something like that? Obviously real for loops, of course.
解决方案
At its absolute simplest, a 2D dimensional array can be created as:
<?php
$emptyArray = array(array());
?>
Or as of PHP 5.4 you can also use:
<?php
$emptyArray = [[]];
?>
这篇关于在PHP中创建一个空的2D数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文