|
|
Use isset() Instead of strlen() - PHP
|
Views : 320
|
|
Tagged in : PHP
|
|
|
Report This Scrap as Inappropriate We request you to choose the appropriate categroy and subcategory that suits your
objectionable concern about the scrap, So that our team can review and find out whether it violates our Guidelines or the
scrap is not suitable for all viewers.
|
Use isset() Instead of strlen()
When you treat strings as arrays, each character in the string is an element in the array. By determining whether a particular element exists, you can determine whether the string is at least that many characters long.
<?php
if (isset($username[5])) {
// The username is at least six characters long.
}?>
Note that the first character is element 0, so $username[5] is the sixth character in $username.
The reason this is slightly faster than strlen() is complicated. The strlen() is a function, and isset() is a language construct.
Generally speaking, calling a function is more expensive than using a language construct.
|
|
By Sanju, On - 2010-02-01 |
|
|
|