I have a usort function with a single line: return 0.
I tried to use it on an Array of stdClass objects, and it changes
their order, how is that possible?
I have a usort function with a single line: return 0. I tried to
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The property you assume is called stability: A stable sorting algorithm will not change the order of elements that are equal.
php’s sorting functions are not stable (because non-stable sorts may be slightly faster). From the documentation of
usort:If you want a stable sorting algorithm, you must implement it yourself.