Internal implementation of PHP's count (array) and strlen (string)

Source: Internet
Author: User


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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.