开发者

PHP declaring empty arrays?

开发者 https://www.devze.com 2023-02-12 07:28 出处:网络
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 ce开发者_高级运维rtain size and THEN go back and f

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 ce开发者_高级运维rtain size and THEN go back and fill it?


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';


You could use array_fill() for that:

$array = array_fill(1, 50, "");   // creates [1]...[50] with "" string
0

精彩评论

暂无评论...
验证码 换一张
取 消