Home>Article>Backend Development> What does php count string return?

What does php count string return?

青灯夜游
青灯夜游 Original
2022-01-26 18:24:10 2170browse

php count string returns "1". Reason: count() is an array method that can return the number of elements in the array; when calculating "count(string)", the string will first be converted into an array with only 1 element, and then the number of elements in the array will be counted. and returns, thus returning the value "1".

What does php count string return?

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

What does the php count string return?

Let’s take a look through the code:

What does php count string return?

The operation result is 1, so the count string returns the value "1".

Cause: Automatic type conversion occurred

count() is an array method that returns the number of elements in the array.

When using the count() function to calculate the length of a string, the system will automatically convert the string into an array with only 1 elementarray("hello"), and then perform the calculation.

//等价于 echo count(array("hello"));

Thus count(string) will return the value 1.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What does php count string return?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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