Home >Backend Development >PHP Tutorial >Two ways to determine string length in PHP
This article mainly introduces relevant information on PHP's judgment of string length. Friends who need it can refer to
Strlen is used to judge the string length in the PHP program.
Method one:
$str = ‘aaaaaa'; if(strlen($str) > 6){ echo "字符串大于6"; }
Method two:
if(isset($str{6}){ }
The above two methods, the second one 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.
Related recommendations:
PHP determines whether the user has logged in. Example analysis
Five ways PHP determines whether the array is empty Commonly used methods
PHP method to determine whether a binary tree is symmetric
##
The above is the detailed content of Two ways to determine string length in PHP. For more information, please follow other related articles on the PHP Chinese website!