PHP Programming Tips
Variable Operations
String Functions
Numeric Functions
Array Functions
Output Functions
- 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% faster than stripos()
- strpos() is 9.7% faster than strstr()
- isset($str{5}) is 176% faster than strlen($str) > 5
- str_replace($str, $str, $str) twice is 17% faster than str_replace(array, array, string)
- list() = explode() is 13% faster than substr($str, strpos($str))
Numeric Functions
- ++$int is 10% faster than $int++
- (float) is 48% faster than settype($var, 'float')
Array Functions
- list() = $array; is 3.4% faster than assigning each variable
- in_array() is 6% faster than array_search
- isset($array[$key]) is 230% faster than array_key_exists()
- !empty($array) is 66% faster than count($array)
Output Functions
- echo is 5% faster than print()
- echo ' '.' ' is 0.44% faster than echo ' ',' '
Comments