$arr = Array (' department ' + = ' Athena ', ' sign ' = 0, ' time ' =& Gt ' June 01, 2015 ', ' surname ' = ' star history ', Array (' Department ' = ' Athena ', ' Sign ' = 0, ' time ' = ' June 02, 2015 ', ' surname ' + ' star history ', Array ( ' Department ' = ' Athena ', ' sign ' + 0, ' time ' = ' June 03, 2015 ', ' surname ' = > ' instantaneous '), Array (' Department ' = ' Athena ', ' sign ' = + 0, ' time ' =& Gt ' June 03, 2015 ', ' surname ' = ' Violet Dragon '), $array =array (), foreach ($arr as $v) {if (!isset ($array [$v [' Surna Me ']) {$array [$v [' Surname ']][' count ']=1; $array [$v [' Surname ']][' time ']= $v [' time ']; }else{$array [$v [' Surname ']][' count ']+=1; $array [$v [' Surname ']][' time '].= ', '. $v [' time ']; }}print_r ($array); "' Output is
' Surname ' = ' star history ',
' Count ' =2
Other
' Surname ' = ' instantaneous ',
' Count ' = 1 is all 1
But this output is not sorted by default
```
How do you put the total number of ' count ' in front of the top?
Reply content:
$arr = Array (' department ' + = ' Athena ', ' sign ' = 0, ' time ' =& Gt ' June 01, 2015 ', ' surname ' = ' star history ', Array (' Department ' = ' Athena ', ' Sign ' = 0, ' time ' = ' June 02, 2015 ', ' surname ' + ' star history ', Array ( ' Department ' = ' Athena ', ' sign ' + 0, ' time ' = ' June 03, 2015 ', ' surname ' = > ' instantaneous '), Array (' Department ' = ' Athena ', ' sign ' = + 0, ' time ' =& Gt ' June 03, 2015 ', ' surname ' = ' Violet Dragon '), $array =array (), foreach ($arr as $v) {if (!isset ($array [$v [' Surna Me ']) {$array [$v [' Surname ']][' count ']=1; $array [$v [' Surname ']][' time ']= $v [' time ']; }else{$array [$v [' Surname ']][' count ']+=1; $array [$v [' Surname ']][' time '].= ', '. $v [' time ']; }}print_r ($array); "' Output is
' Surname ' = ' star history ',
' Count ' =2
Other
' Surname ' = ' instantaneous ',
' Count ' = 1 is all 1
But this output is not sorted by default
```
How do you put the total number of ' count ' in front of the top?
Use PHP's Usort function for custom sorting
$b['count'] ? -1 : 1); } $array = array(...); //array为您的数据数组 usort($array, 'my_sort'); print_r($array);
Can write down a custom sort
php
function my_sort($a, $b) { return -($a['count'] - $b['count']);//降序 } uasort($array, "my_sort");print_r($array);
Two person The answer is good, but can not point to two adopted ~ ~ ~