PHP length calculation is easy to confuse the problem analysis, PHP lengths calculation Confusion _php Tutorial

Source: Internet
Author: User
Tags php regular expression

PHP length calculation Confusion in the analysis of the problem of easy to confuse the length calculation


The example in this paper is about the confusion of length calculation in PHP. Share to everyone for your reference, as follows:

are often confused by the character functions of arrays and strings in PHP, as summarized below:

strlen ($string) function : Calculates the length of a string;

sizeof ($string, $mode) function : It is the alias of the Count () function, and the count () function is as follows:

int count (mixed var [, int mode])

Returns the number of cells in Var, usually an array, with only one cell for any other type.

For an object, if SPL is installed, you can invoke count () by implementing the countable interface. The interface has only one method count (), and this method returns the return value of the count () function.

If Var is not an array type or an object that implements the countable interface, 1 is returned, with one exception, and if Var is NULL then the result is 0.

Note: The optional mode parameter is available from PHP 4.2.0.

If the optional mode parameter is set to Count_recursive (or 1), COUNT () counts recursively on the array. is especially useful for calculating all cells of a multidimensional array. The default value for mode is 0. Count () does not recognize infinite recursion.

In short, the string with strlen (), the array with sizeof ().

More readers interested in PHP related content can view this site topic: "PHP Operations Office Document Skills Summary (including word,excel,access,ppt)", "PHP array" operation Skills Daquan, "PHP Sorting algorithm Summary", " PHP common traversal algorithm and skills summary, "PHP Data structure and algorithm tutorial", "PHP Programming Algorithm Summary", "PHP Math Skills Summary", "PHP Regular Expression Usage summary", "PHP operation and operator Usage Summary", "PHP String Usage Summary" and "PHP Common database Operation Skills Summary"

I hope this article is helpful to you in PHP programming.

http://www.bkjia.com/PHPjc/1133065.html www.bkjia.com true http://www.bkjia.com/PHPjc/1133065.html techarticle PHP in the calculation of the length of the problem is easy to confuse analysis, PHP length calculation confusion in this paper, the example of the length calculation in PHP is easy to confuse problems. Share to everyone for your reference, specific ...

  • 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.