note 123607 added to function.strcmp
| From: | kgun!mail!com@php.net | Date: | Tue, 12 Feb 2019 22:16:31 +0000 |
| Subject: | note 123607 added to function.strcmp | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-210234@lists.php.net to get a copy of this message | ||
In case you want to get results -1, 0 or 1 always, like JS indexOf();
<?php
function cmp(string $str1, string $str2): int {
return ($str1 > $str2) - ($str1 < $str2);
}
$str1 = 'a';
$str2 = 'z';
var_dump(cmp($str1, $str2), strcmp($str1, $str2));
//=> int(-1) int(-25) int(-25)
$str1 = 'a';
$str2 = '1';
var_dump(cmp($str1, $str2), strcmp($str1, $str2));
//=> int(1) int(48) int(48)
?>
----
Server IP: 208.43.231.9
Probable Submitter: 185.85.3.142 (proxied: 77.111.247.140)
----
Manual Page -- http://php.net/manual/en/function.strcmp.php
Edit -- https://master.php.net/note/edit/123607
Del: integrated -- https://master.php.net/note/delete/123607/integrated
Del: useless -- https://master.php.net/note/delete/123607/useless
Del: bad code -- https://master.php.net/note/delete/123607/bad+code
Del: spam -- https://master.php.net/note/delete/123607/spam
Del: non-english -- https://master.php.net/note/delete/123607/non-english
Del: in docs -- https://master.php.net/note/delete/123607/in+docs
Del: other reasons-- https://master.php.net/note/delete/123607
Reject -- https://master.php.net/note/reject/123607
Search -- https://master.php.net/manage/user-notes.php