Home » » strcmp

strcmp

Written By 1 on Sunday, September 30, 2012 | 8:33 AM

int strcmp ( string $str1 , string $str2 )

Binary safe string comparison


If you rely on strcmp for safe string comparisons, both parameters must be strings, the result is otherwise extremely unpredictable.

For instance you may get an unexpected 0, or return values of NULL, -2, 2, 3 and -3.



strcmp("5", 5) => 0

strcmp("15", 0xf) => 0

strcmp(61529519452809720693702583126814, 61529519452809720000000000000000) => 0

strcmp(NULL, false) => 0

strcmp(NULL, "") => 0

strcmp(NULL, 0) => -1

strcmp(false, -1) => -2

strcmp("15", NULL) => 2

strcmp(NULL, "foo") => -3

strcmp("foo", NULL) => 3

strcmp("foo", false) => 3

strcmp("foo", 0) => 1

strcmp("foo", 5) => 1

strcmp("foo", array()) => NULL + PHP Warning

strcmp("foo", new stdClass) => NULL + PHP Warning

strcmp(function(){}, "") => NULL + PHP Warning


Curso PHP-MySQL. Buscar y reemplazar substrings

0 Comment:

Post a Comment