且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在PHP中创建一个空的2D数组?

更新时间:2023-11-27 13:41:52

在其绝对最简单的情况下,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 = [[]];
?>