PHP - Multiple uasort functions breaks sorting

前端 未结 3 1350
悲哀的现实
悲哀的现实 2020-12-01 22:18

I have a multidimensional array that stores people.

Array (
   id93294 => (array (
             Name => \"Tom Anderson\",
             Birthday => \         


        
3条回答
  •  自闭症患者
    2020-12-01 23:17

    Excellent question.

    This pseudo-code comes from the definition of the problem you gave and is intended to be the callback function given to uasort. I cannot fill in the details because you've omitted the code you're using; hopefully this leads you on the right track.

    function compare(p1, p2):
        if birthdays of p1 and p2 are not the same
            compare by birthday
        else
            compare by hometown
    

    If someone could verify that this is a valid comparison function for a sort algorithm in the comments, I would be grateful.

提交回复
热议问题