What does php count string return?

青灯夜游
Release: 2023-03-15 06:36:01
Original
2169 people have browsed it

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:

<?php
$str="hello";
echo count($str);
?>
Copy after login

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 element array("hello"), and then perform the calculation.

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

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!