PHP declares empty arrays?

I need to make a two-dimensional array based on the number of permissions that say about the parts of the car that are presented in the form. Is it possible to declare an array of a certain size, and THEN go back and fill it?

+4
source share
2 answers

PHP arrays are dynamically allocated. There is no reason to create it ahead of time. Just start using indexes as needed:

$myNewVar[0] = 'data'; 
+10
source

You can use array_fill () for this:

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

Source: https://habr.com/ru/post/1340272/


All Articles