Home >Backend Development >PHP Tutorial >Two methods for determining string length in PHP are very practical, strings are very practical_PHP tutorial
To determine the length of a string in a PHP program, you can use strlen.
Method 1:
$str = ‘aaaaaa'; if(strlen($str) > 6){ echo "字符串大于6"; }
Method 2:
if(isset($str{6}){ }
The second method above 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 faster! So the second method can be used when determining whether a string is greater than or less than a number of characters.