Interesting trick about isset() of PHP

Base on Mike on April 16th, 2008

strlen() is one of most expensive functions so if You want find out if string has more than 100 chars You can do:
if (isset($string{100})) {
echo ‘String is longer than 10 chars’;
}

isset() is not a function – it’s language construct – so it works faster than usually functions and isset() doesn’t have to count all $string one by one char.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s