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;
}
?>