March 29th, 2005. Tagged: PHP certification

strcmp() compares two strings and gives -1, 0 or 1 depending on wheather the first string is "smaller", equal to or greater than the second one.

< ?php echo strcmp('aa','bb'); // prints -1 echo strcmp('bb','bb'); // prints 0 echo strcmp('zz','yy'); // prints 1 ?>

Thus being said there's an error in the php certification guide that explains the strcasecmp() function, which is the same as strcmp() only case insensitive. There is a snippet in the book that goes like:
< ?php $a = 'hello'; if (strcasecmp($a, 'HELLO')) { echo 'the same'; }?>
The book says that the echo will be executed but it will not, as the comparison will return 0, since 'hello' and 'HELLO' are the same string when regarded at case-insensitively.

Tell your friends about this post on Facebook and Twitter

Sorry, comments disabled and hidden due to excessive spam.

Meanwhile, hit me up on twitter @stoyanstefanov