note 126955 added to function.array-uintersect
| From: | RyanC at main dot php dot net | Date: | Fri, 25 Mar 2022 04:17:57 +0000 |
| Subject: | note 126955 added to function.array-uintersect | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-217765@lists.php.net to get a copy of this message | ||
If you're rolling your own comparison function, keep in mind that the spaceship operator (i.e.
<=>) can be your best friend. It's been around since PHP7. https://www.php.net/manual/en/language.operators.comparison.php
So, for instance, instead of a clunky function like:
<?php
function myFunction($v1, $v2) {
if ($v1 === $v2) {
return 0;
}
if ($v1 > $v2) return 1;
return -1;
}
?>
You can simplify it to:
<?php
function myFunction($v1, $v2) {
return $v1 <=> $v2;
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.135 (proxied: 2601:601:e03:ed0:b5e7:9d0c:4e14:73b0)
----
Manual Page -- https://php.net/manual/en/function.array-uintersect.php
Edit -- https://main.php.net/note/edit/126955
Del: integrated -- https://main.php.net/note/delete/126955/integrated
Del: useless -- https://main.php.net/note/delete/126955/useless
Del: bad code -- https://main.php.net/note/delete/126955/bad+code
Del: spam -- https://main.php.net/note/delete/126955/spam
Del: non-english -- https://main.php.net/note/delete/126955/non-english
Del: in docs -- https://main.php.net/note/delete/126955/in+docs
Del: other reasons-- https://main.php.net/note/delete/126955
Reject -- https://main.php.net/note/reject/126955
Search -- https://main.php.net/manage/user-notes.php