I have this multidimensional array:
Array
(
[0] => Array
(
[0] => 2012-02-26 07:15:00
)
[1] => Array
(
[0] => 2012-02-26 17:45:00
[1] => 2012-02-26 18:55:00
)
[2] => Array
(
[0] => 2012-02-26 18:55:00
[1] => 2012-02-26 17:45:00
)
[3] => Array
(
[0] => 2012-02-26 18:57:00
[1] => 2012-02-26 17:45:00
[2] => 2012-02-26 18:55:00
)
When I count subarrays I get this 1,2,2,3. How could I receive it in 3,2,2,1? I need to get for example last 3 subarrays with the highest subarray count (DESC, it means 3,2,2). How can I achieve this?
It seems to me that all of the other answers are working too hard.
usort()
,count()
, andforeach()
aren't necessary and when I triednatsort()
it gave me:<b>Notice</b>: Array to string conversion in <b>[...][...]</b>
.rsort() will put the longest subarrays first.
Code:
Output:
If you want to implement some additional sorting to break the length-ties (like between your two 2-element subarrays), then you will need to specify that in your question.
You can achieve it by utilizing usort function.
This might be what you seek:
You might want to omit the actual sorting if the values you have are already in order.