note 68615 added to function.strcmp

From: Date: Thu, 03 Aug 2006 14:36:53 +0000
Subject: note 68615 added to function.strcmp
Groups: php.notes 
Request: Send a blank email to php-notes+get-115517@lists.php.net to get a copy of this message
The definition of return values of this function is listed correctly on this page, however, there is a common misconception in the notes posted here previously from users. A previous poster said: If $str1 == $str2 strcmp return 0. If $str1  > $str2 strcmp return 1. If $str1  < $str2 strcmp return -1. That is incorrect, please look at the definition of the function at the top of this page. It returns less than 0 if str1 is less than str2. Note the phrase "less than", it does not return just -1, but any negative value. The same happens when str1 is greater than str2, but it returns a positive, non-zero value. It returns a positive value that can be 1, or any number thereafter. strcmp() returns a number that is the difference between the two strings starting with the last character that was found to be similar. Here is an example: $output = strcmp("red", "blue"); The variable $output with contain a value of 16 ---- Server IP: 216.194.113.175 Probable Submitter: 12.37.17.116 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.strcmp.php Edit -- https://master.php.net/note/edit/68615 Del: integrated -- https://master.php.net/note/delete/68615/integrated Del: useless -- https://master.php.net/note/delete/68615/useless Del: bad code -- https://master.php.net/note/delete/68615/bad+code Del: spam -- https://master.php.net/note/delete/68615/spam Del: non-english -- https://master.php.net/note/delete/68615/non-english Del: in docs -- https://master.php.net/note/delete/68615/in+docs Del: other reasons-- https://master.php.net/note/delete/68615 Reject -- https://master.php.net/note/reject/68615 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#115517) next »