Good time.
I have a multidimensional array $a like this:
$a[0] = [1,5,2022-04-01,2022-04-20, 5, 10:30:00, 11:30:00, 1, 700];
$a[1] = [1,5,2022-04-05,2022-04-15, '', 10:30:00, 11:30:00, 1, 800];
$a[2] = [1,0,2022-04-07,2022-04-15, '', '', '', 1, 800];
$a[3] = [1,5,2022-04-06,2022-04-16, '', '', '', 0, 900];
$a[4] = [1,5,2022-04-07,2022-04-12, '', '', '', 0, 600];
...
$a[n] = [1,0,2022-04-06,2022-04-16, 4, '', '', 0, 1100];
First four elements in each $a[]
are always not-empty. Elements from 5 to 7, as you see, can be empty or not. Element 8 can be only 0 or 1, but not empty. And the last element is always not-empty.
I want to sort this multi-dimensional array with some "score" logic:
First rule:
- if we have empty all 5, 6 and 7 elements (like we have in $a[2]) - the score of this $a[] is 1
- if we have empty only 6 and 7 elements, and 5 is not-empty, (like we have in $a[n]) - the score of this $a[] is 2
- if we have empty only 5 element, but 6 and 7 are not-empty (like we have in $a[1]) - the score of this $a[] is 3
- if we have all 5, 6 and 7 elements not-empty (like we have in $a[0]) - the score of this $a[] is 4
Also second rule:
- if score for two $a[] is the same, but 8th element is different, the sorting function have to put one of them with "1" as 8th parameter higher, than another
And last rule:
- if two (or more) $a[] have the same score and and also 8th parameter is the same, the sorting function have to put higher those, that have less difference between 4 and 3 parameter (in fact it is a difference between 2 dates).
So, the result have to be from highest to lowest:
[1,5,2022-04-01,2022-04-20, 5, 10:30:00, 11:30:00, 1, 700]; // 4 scores
[1,5,2022-04-05,2022-04-15, '', 10:30:00, 11:30:00, 1, 800]; //3 scores
[1,0,2022-04-06,2022-04-16, 4, '', '', 0, 1100]; // 2 scores
[1,0,2022-04-07,2022-04-15, '', '', '', 1, 800]; // 1 score + 8th parameter is "1"
[1,5,2022-04-07,2022-04-12, '', '', '', 0, 600]; // 1 score + dates difference is 5 days
[1,5,2022-04-06,2022-04-16, '', '', '', 0, 900]; // 1 score + dates difference is 10 days
How it can be done in php?