79558768

Date: 2025-04-06 21:34:10
Score: 0.5
Natty:
Report link

Oh, found the answer. usort takes the callback name as a string, so the code should read:

<!DOCTYPE html>
<html>
<body>
<?php
function cb($l1, $l2) {
    if($l1 == $l2) return 0;
    return ($l1 < $l2) ? -1 : 1 ;
}
$res[0] = 102;
$res[1] = 101;
echo var_dump($res);
echo "<br>";
usort($res, "cb"); // notice the quotes around "cb"
echo var_dump($res);
?>
</body>
</html>

I read that earlier PHP versions were tolerant and implicitly quoted such calls...

Reasons:
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: L. Levrel