How do I list the time array together?

Source: Internet
Author: User
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 '];});
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.