note 120197 added to language.operators.comparison
| From: | MustaRoad | Date: | Mon, 21 Nov 2016 17:58:05 +0000 |
| Subject: | note 120197 added to language.operators.comparison | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-207261@lists.php.net to get a copy of this message | ||
I think PHP compare arrays with <=> operator like the following:
echo [12, 11, 100] <=> [12, 20, 3];
it initiate a counter for this comparison and then compare each entry like
following:
counter for this comparison will initiated with zero:
counter = 0
after that it compare like following:
a == b this mean the count operation will be counter = counter + 0
a > b this mean the count will be counter = counter + 1
a < b this mean the count will be counter = counter - 1
12 == 12 -----> counter = counter + 0
11 < 20 -------> counter = counter - 1
100 > 3 -------> counter = counter + 1
and if the counter remain zero after these comparisons, it will try to find the first different
value and produce it as a final result, SO because the first element is 12 in both arrays the second
one will be tested and because it is different the final result will depend on it and
'echo' will produce -1 because 11 is less than 20.
test the following to be sure:
echo ([12, 100, 11] <=> [12, 3 ,20]).PHP_EOL;
echo ([12, 11, 100] <=> [12, 20 ,3]).PHP_EOL;
echo ([11, 12, 100] <=> [20 ,12 ,3]).PHP_EOL;
it just an idea I don't test it carefully BUT to help in some way thanks!!
----
Server IP: 72.52.91.14
Probable Submitter: 37.236.112.15
----
Manual Page -- http://php.net/manual/en/language.operators.comparison.php
Edit -- https://master.php.net/note/edit/120197
Del: integrated -- https://master.php.net/note/delete/120197/integrated
Del: useless -- https://master.php.net/note/delete/120197/useless
Del: bad code -- https://master.php.net/note/delete/120197/bad+code
Del: spam -- https://master.php.net/note/delete/120197/spam
Del: non-english -- https://master.php.net/note/delete/120197/non-english
Del: in docs -- https://master.php.net/note/delete/120197/in+docs
Del: other reasons-- https://master.php.net/note/delete/120197
Reject -- https://master.php.net/note/reject/120197
Search -- https://master.php.net/manage/user-notes.php