The function to test the length of the string in PHP is strlen, but today I find it more efficient to use isset, saying no, you don't believe me. Let me give you two examples to see. Learn PHP, get a string in PHP has a strlen function, here and you share a in some specific circumstances to judge the length of the string is more efficient way. Take a look at the following two code execution efficiency, you understand the implementation of code to understand the idea, the code is as follows:
- <?php
- //Use strlen mode
- $arr = ' 123456 ';
- $sTime = microtime (1);
- if (strlen ($arr) > 6) {
- //echo 1;
- }
- echo microtime (1)- $sTime;
- //output: 0.00035595893859863
- /*-------------------------------------*/
- //Use the Isset ($arr {}) mode
- $arr = ' 123456 ';
- $sTime = microtime (1);
- //Open source software: vcphp.com
- if (!isset ($arr {6})) {
- //echo "1RN";
- }
- echo microtime (1)- $sTime;
- Output: 0.00019097328186035
- ?>
|
Enterprise Template site Sharing
PHP more efficient example of character length judgments