PHP声明空数组?(PHP declaring empty arrays?)

我必须根据表单上提交的汽车零件的数量制作一个二维数组。 是否可以声明一个特定大小的数组,然后返回并填充它?

I have to make a two-dimensional array based on the number of lets say car parts that is submitted on a form. Is it possible to declare an array of a certain size and THEN go back and fill it?

最满意答案

PHP数组是动态分配的。 没有理由提前创建它。 只需在需要时使用索引即可:

$myNewVar[0] = 'data';

PHP arrays are dynamically allocated. There's no reason to create it ahead of time. Just start using the indexes as you need them:

$myNewVar[0] = 'data';PHP声明空数组?(PHP declaring empty arrays?)

我必须根据表单上提交的汽车零件的数量制作一个二维数组。 是否可以声明一个特定大小的数组,然后返回并填充它?

I have to make a two-dimensional array based on the number of lets say car parts that is submitted on a form. Is it possible to declare an array of a certain size and THEN go back and fill it?

最满意答案

PHP数组是动态分配的。 没有理由提前创建它。 只需在需要时使用索引即可:

$myNewVar[0] = 'data';

PHP arrays are dynamically allocated. There's no reason to create it ahead of time. Just start using the indexes as you need them:

$myNewVar[0] = 'data';