Home  >  Article  >  Backend Development  >  Two ways to determine the length of a string in PHP

Two ways to determine the length of a string in PHP

怪我咯
怪我咯Original
2017-07-04 11:49:172477browse

This article mainly introduces relevant information on PHP's judgment of string length. Friends who need it can refer to the

string length judgment in the php program. You can use strlen .

Method one:

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

Method two:

if(isset($str{6}){
}

The second method is more efficient.

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

The above is the detailed content of Two ways to determine the length of a string in PHP. 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