Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of easily confused length calculation in php

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you the "php length calculation easy to confuse example analysis", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn the "php length calculation easy to confuse example analysis" this article.

The details are as follows:

Often confused by the character functions of arrays and strings in php, here's a summary:

Strlen ($string) function: calculates the length of a string

Sizeof ($string,$mode) function: it is an alias for the count () function, and the count () function is as follows:

Int count (mixed var [, int mode])

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

For objects, if SPL is installed, you can call count () by implementing the Countable interface. The 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 is returned, with one exception, if var is NULL, the result is 0.

Note: optional mode parameters are available since PHP 4.2.0.

If the optional mode parameter is set to COUNT_RECURSIVE (or 1), count () will count the array recursively. It is especially useful for calculating 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.

The above is all the contents of the article "sample Analysis of easily confused length calculation in php". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report