Home > Backend Development > PHP Tutorial > String length judgment in php program

String length judgment in php program

墨辰丷
Release: 2023-03-30 12:02:01
Original
2285 people have browsed it

This article mainly introduces the judgment of string length in PHP program. Interested friends can refer to it. I hope it will be helpful to everyone.

Method one:

$str = ‘aaaaaa';
if(strlen($str) > 6){
 echo "字符串大于6";
}
Copy after login

Method two:

if(isset($str{6}){
}
Copy after login

The second method is more efficient.

In PHP, all variables are saved using a structure -zval. Although strlen directly obtains the len, there is still a function call, and isset is a syntax structure of PHP, so it is more quick! So the second method can be used when determining whether a string is greater than or less than a number of characters.

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

php method to create a multi-level directory complete encapsulation class

PHP infinite loop acquisition MySQL data

php determines whether the required parameters in the function exist

The above is the detailed content of String length judgment in php program. For more information, please follow other related articles on the PHP Chinese website!

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