Answer the question
In order to leave comments, you need to log in
Why is the sort code not working as expected?
Here is the code that sorts a menu in PHP. I know that this can be done directly with the base, but I want to understand how it works.
usort($menu, function ($a, $b) {
return (0
|| ($a["level"] - $b["level"])
|| ($a["parent_id"] - $b["parent_id"])
|| ($a["id"] - $b["id"])
);
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question