Edit report at https://bugs.php.net/bug.php?id=61887&edit=1
ID: 61887 Updated by: johan...@php.net Reported by: vorcak dot jan at gmail dot com Summary: Behaviour of function given to usort -Status: Open +Status: Not a bug Type: Feature/Change Request Package: *General Issues PHP Version: Irrelevant Block user comment: N Private report: N New Comment: The documentation says: The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second. The implementation is using return retval < 0 ? -1 : retval > 0 ? 1 : 0; So your request is already fullfilled. Previous Comments: ------------------------------------------------------------------------ [2012-05-01 07:42:22] vorcak dot jan at gmail dot com Description: ------------ If you try to sort and array with the custom function using usort, you have to return -1, 0 or 1. It would be nice if user can return any integer and usort function would decide based on the sgn() value // after few years programming in Python/Java I had problems why my code doesn't work, because I just returned value $a-$b not sgn($a-$b) Expected result: ---------------- I'd expect usort function to work with any integer, not just -1, 0, 1 Actual result: -------------- Usort function shuffle the array, it doesn't give me any warning ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=61887&edit=1