Posts

Ternary Operators

This operator takes three arguments – a condition, a result for true, and a result for false. It is a shortcut of doing if statements. Here’s an example:     $result = ($a < 16) ? 'true' : 'false';     if ($a < 16) {         $result = 'true';     } else {         $result = 'false';     } Use Facebook to Comment on this Post Ternary Operators

Cheat Sheets & Quick Reference Cards for Developers | DevCheatSheet.com

Cheat Sheets & Quick Reference Cards for Developers | DevCheatSheet.com

PHP 5.4 beta1 released

The PHP development team announced the first beta release of PHP 5.4. PHP 5.4 includes new language features and removes several legacy (deprecated) behaviors. THIS IS A DEVELOPMENT PREVIEW - DO NOT USE IT IN PRODUCTION!

How to check browser cookie enabled with php and javascript

Cookies are typically used by web servers to perform functions such as tracking your visits to websites, enabling you to log in to sites, and storing your shopping cart. Cookies can be used to interaction between Javascript and Server Side Scripts like PHP.Cookies also used to transfer small amount of data between one page to other pages via HTTP headers .If user disables this cookies or user’s browser won’t support the interaction between JS and PHP fails.So we must ensure user must enable these Cookies. Checking with Javascript if (navigator.cookieEnabled == 0) { alert("You need to enable cookies for this site to load properly!"); } Checking with PHP If user disables Javascript we fail to check the Cookie enabled or not.So we check on the server side also.below PHP snippet check the Cookie enabled or not. function check_cookie(){ if (setcookie("test", "test", time() + 360)) { if (isset ($_COOKIE['test'])) { return true; } } return false; }

PHP 5.3.8 Released!

All PHP users should note that the PHP 5.2 series is NOT supported anymore. All users are strongly encouraged to upgrade to PHP 5.3.8.

PHP Programming Tips

Functions And Methods Function And Method Calling call_user_func() is 54% slower than just calling the function call_user_func() is 59% slower than calling a static method call_user_func() is 65% slower than calling an object method function() is 119% faster than static::method() $this->method() is 116% faster than static::method() declared static::method() is 93% faster than static::method() Functions General Pass by reference is 3% faster than Return by reference No reference is 1.7% faster than Return by reference

PHP Programming Tips

Variable Operations Operating on an initialized variable is 376% faster than operating on an unitialized variable. Constants are 146% slower than variables Local variables are 9.9% faster than global variables String Functions 'String' is 0.26% faster than "String" "String" is 4% faster than HEREDOC syntax "String\n" is 108% faster than 'String'."\n" 'String'.$var is 28% faster than "String$var" 'string '.$var.' string' is 55% faster than sprintf('string %s string', $var) "\n" is 70% faster than chr(10) strnatcmp() is 4.95% faster than strcmp() strcasecmp() is 45% faster than preg_match() strcasecmp() is 6.6% faster than strtoupper($string) == "STRING" strcasecmp() is 13% faster than strnatcasecmp() strtr($string, $string1, $string2) is 10% faster than str_replace() str_replace() is 161% faster than strtr($string, $array) stristr() is 10%...