Home > Backend Development > PHP Tutorial > Analysis of confusing problems in length calculation in PHP, PHP length calculation confusion_PHP tutorial

Analysis of confusing problems in length calculation in PHP, PHP length calculation confusion_PHP tutorial

WBOY
Release: 2016-07-12 08:50:49
Original
977 people have browsed it

Analysis of the confusion about length calculation in PHP, PHP length calculation confusion

The example of this article tells about the confusion about length calculation in PHP. Share it with everyone for your reference, the details are as follows:

I am often confused by the character functions of arrays and strings in PHP. Here is a summary:

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

sizeof($string,$mode) function: It is an alias of the count() function. The count() function is as follows:

int count ( mixed var [, int mode] )

Returns the number of cells in var, usually an array, any other type has only one cell.

For objects, if SPL is installed, count() can be called by implementing the Countable interface. This interface has only one method, count(), which returns the return value of the count() function.

If var is not an array type or an object that implements the Countable interface, 1 will be returned, with one exception, if var is NULL the result is 0.

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

If the optional mode parameter is set to COUNT_RECURSIVE (or 1), count() will count the array recursively. Particularly useful for computing all elements of a multidimensional array. The default value for mode is 0. count() does not recognize infinite recursion.

In short, use strlen() for strings and sizeof() for arrays.

Readers who are interested in more PHP-related content can check out the special topics of this site: "Summary of PHP office document operation skills (including word, excel, access, ppt)", "Complete of PHP array (Array) operation skills", " PHP Sorting Algorithm Summary", "PHP Common Traversal Algorithms and Techniques Summary", PHP Data Structure and Algorithm Tutorials, PHP Programming Algorithm Summary, PHP Mathematical Operation Techniques Summary, PHP Regular Expression Usage Summary, "Summary of PHP operations and operator usage", "Summary of PHP string usage" and "Summary of common PHP database operation skills"

I hope this article will be helpful to everyone in PHP programming.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1133065.htmlTechArticleAnalysis of the confusion about length calculation in php, php length calculation confusion This article tells the example about length calculation in php Confusing question. Share it with everyone for your reference, specifically...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template