Array results after the database has been printed:
Array( [0] => Array ( [department] => 雅典娜 [sign] => 0 [time] => 2015年06月01日 [surname] => 星史 ) [1] => Array ( [department] => 雅典娜 [sign] => 0 [time] => 2015年06月02日 [surname] => 星史 ) [2] => Array ( [department] => 雅典娜 [sign] => 0 [time] => 2015年06月03日 [surname] => 瞬 ) [3] => Array ( [department] => 雅典娜 [sign] => 0 [time] => 2015年06月03日 [surname] => 紫龙 )
I want to count the same array, for example, there are two arrays of star history, statistics are 2, others are 1.
Then the array notation is
$array=array();foreach($上面打印的数组 as $v){ if(!isset($array[$v['surname']])){ $out_put[$v['surname']]['time']=$v['time']; $array[$v['surname']]['count']=1; }else{ $array[$v['surname']]['count']=$array[$v['surname']]['count']+1; }}
And then print out
Array( [星史] => Array ( //问题再这里,如何数组输出多个时间呢 [time] = 2015年06月01日、2015年06月02日 [time] =2015年06月01日; [count] => 2 ) [瞬] => Array ( [time] =2015年06月03日; [count] => 1 ) [紫龙 => Array ( [time] =2015年06月03日; [count] => 1 ))
How does this print output time?
Reply content:
Array results after the database has been printed:
Array( [0] => Array ( [department] => 雅典娜 [sign] => 0 [time] => 2015年06月01日 [surname] => 星史 ) [1] => Array ( [department] => 雅典娜 [sign] => 0 [time] => 2015年06月02日 [surname] => 星史 ) [2] => Array ( [department] => 雅典娜 [sign] => 0 [time] => 2015年06月03日 [surname] => 瞬 ) [3] => Array ( [department] => 雅典娜 [sign] => 0 [time] => 2015年06月03日 [surname] => 紫龙 )
I want to count the same array, for example, there are two arrays of star history, statistics are 2, others are 1.
Then the array notation is
$array=array();foreach($上面打印的数组 as $v){ if(!isset($array[$v['surname']])){ $out_put[$v['surname']]['time']=$v['time']; $array[$v['surname']]['count']=1; }else{ $array[$v['surname']]['count']=$array[$v['surname']]['count']+1; }}
And then print out
Array( [星史] => Array ( //问题再这里,如何数组输出多个时间呢 [time] = 2015年06月01日、2015年06月02日 [time] =2015年06月01日; [count] => 2 ) [瞬] => Array ( [time] =2015年06月03日; [count] => 1 ) [紫龙 => Array ( [time] =2015年06月03日; [count] => 1 ))
How does this print output time?
php
$arr = Array (' department ' + = ' Athena ', ' sign ' = + 0, ' time ' = ' 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 ' =& Gt ' instantaneous '), Array (' Department ' = ' Athena ', ' sign ' = + 0, ' time ' = ' June 03, 2015 ', ' surname ' + ' Violet Dragon '); $array =array (); foreach ($arr as $v) {if (!isset ($array [$v [' Surnam E ']]) {$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); Uasort ($array, function ($a, $b) {return $b [' count ']-$a [' count '];});