0

I have the following array of objects. I need to somehow sort these so that it returns the array with Partials then Successes then Decline while still keeping the grouping on start the same. So I would need to somehow sort each array by day and then do the custom sort by title so that it can show Partials then Success then Declines. Is this possible?

[0] => stdClass Object
    (
        [start] => 2020-09-29T00:00:00-04:00
        [allDay] => 1
        [title] => Successes
        [test] => 3 Successes
    )

[1] => stdClass Object
    (
        [start] => 2020-09-29T00:00:00-04:00
        [allDay] => 1
        [title] => Partials
        [test] => 6 Partials
    )

[2] => stdClass Object
    (
        [start] => 2020-09-29T00:00:00-04:00
        [allDay] => 1
        [title] => Declines
        [test] => 10 Declines
    )

[3] => stdClass Object
    (
        [start] => 2020-10-01T00:00:00-04:00
        [allDay] => 1
        [title] => Successes
        [test] => 0 Successes
    )

[4] => stdClass Object
    (
        [start] => 2020-10-01T00:00:00-04:00
        [allDay] => 1
        [title] => Partials
        [test] => 0 Partials
    )

[5] => stdClass Object
    (
        [start] => 2020-10-01T00:00:00-04:00
        [allDay] => 1
        [title] => Declines
        [test] => 4 Declines
      )  

I have tried using a usort on the title, but then that breaks the start date sort already in place. I need to somehow sort the titles in the order described above while still keeping the arrays grouped by the same start value.

Keep in mind these are arrays of objects, and that a traditional sort wont yield the results in proper order Partial Success Declined. So a more custom solution is required.

q_w_d
  • 31
  • 3
  • 2
    Does this answer your question? [Sort multidimensional array by multiple keys](https://stackoverflow.com/questions/3232965/sort-multidimensional-array-by-multiple-keys) – TCooper Oct 14 '20 at 16:53
  • No not really as mine are objecrts, and that is only dealing with arrays. I will get an error trying to use object of type stdClass as array with that solution. My issue is more complex as it the titles are not easily sortable, sorting asc or dsc wont yeild partial success declined. – q_w_d Oct 14 '20 at 17:40
  • https://stackoverflow.com/questions/16199407/array-multisort-with-multi-dimensional-object-array - try taking a look here as well for objects, I'm too noob to add multiple links to the duplicate close tag lol. You can also add a value named "sort" in each object based on whether it is partials(0), successes(1), declines(2), and sort on that value instead of the title. – TCooper Oct 14 '20 at 17:44

0 Answers0