What is the time complexity of getting an element in an array in PHP?

I have little knowledge of how arrays are implemented in PHP, and they know that for most OOP languages, complexity is one of the O (1) constant time for an array of a predefined type. So what is the deal in PHP with dynamic typing, array expansion, etc.?

+3
source share
1 answer

The array.c in the PHP source code shows that they are implemented as hash tables, which usually means O (1) (actually it is O (N), if you are very strict, but can be just as bad, like O (log N)) to search for an item.

, . 10, 100, 1000, 10000, 100000, 1000000 .. , , .

+2

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


All Articles