开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜