is the internal implementation of the count (array) and strlen (string) of PHP a direct display of a length variable, or how many elements are there in a number of times?
It's about my understanding of the efficiency of these 2 functions.
I hope that Gao can from the C source of PHP to talk about. There is no source code to see the source know that said also OK.
1. When count is executed, is there a number of "statistics per" child elements behind it?
2, strlen execution when there is no "statistics" the number of characters?
==========
I have found PHP strlen source, alas sank few people ...
I'm looking for count.
=================
Conclusion
Strlen directly returns the length variable, without calculation. Efficiency O (1)
Count-by-element, a large number of calculations occur. Efficiency O (N)
----------------------------------------------
Count is for the array, the return is the length of the array, in the implementation, the array is a hash table, count is the number of elements of this table is counted
Strlen is for the string, the return is the length of the string, that is, the number of characters in the string, in the implementation, have not seen unclear.
In use, strlen is not used to count the number of arrays,
Although count can pass in a string as a parameter, it returns an effect that is equivalent to the count (array), or 1. The meaning of returning with strlen is different.
questioning
Read my question first, I did not ask the PHP level function, the function is written in the manual. Ask is
1, count when the execution of the number of "child element" is not counted?
2, strlen the number of "characters" on the back of the execution?
Test instructions The 2 sentences together to ask.
Note:
The sizeof () function calculates the number of cells in an array or the number of properties in an object.
The function is the alias of Count ().
Baidu knows what to see on the
Source:
Http://zhidao.baidu.com/link?url=uTqPQf48jCkbyHA_cJMcfLSiw5GQd7i6KOWqEEnwVoTWe3YlMqYWc2KLF_3cvaKCl7XmNgw2XmKhql6fJZ0zc_
Internal implementation of PHP's count (array) and strlen (string)