D
D
Dmitry Nosikov2017-08-09 11:59:58
PHP
Dmitry Nosikov, 2017-08-09 11:59:58

Are empty array values ​​created when an element is written to a new array at index 100?

Good afternoon, colleagues! Please tell me information on this issue, if, for example, we create a new empty array, and write a value to it with a key of 100 and a value of 1, $test[100] = 1;
Are empty elements created before element with key 100? count shows the length of the array dimension = 1.
The need for this kind of arrays arises because it is convenient to access individual elements of this array by keys that are equal to the ID of records from the database.
Why did the question arise? I remember somewhere a long time ago I came across an article (if memory serves), which said that PHP creates pseudo-empty elements that are not visible anywhere, but they take up memory and this practice is not good.
Can you please tell me if this is so and if so, how bad is this practice?
Thank you all in advance for your help and any advice on this matter.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Dobryshin, 2017-08-09
@deimon260993

No, they are not created.
You
could find out on your own, for example, by printing out the contents of the array:
var_dump($array);

A
Alexander Lysenko, 2017-08-09
@LysenkoSasha

Use an associative array and that's it :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question