Sort the PHP array and take the number of array bars

Source: Internet
Author: User

Public Function invitation ($appId, $type) {
$arr = db ("indicated")->field ("Id,superior,avatar,nickname")
->where (' superior=0 ')
->select ();
foreach ($arr as $k = = $v) {
$where = Self::invitationtime ($type, $v);
$arr [$k] [' count '] = db ("indicated")
->where ($where)
->count ();
}
foreach ($arr as $key = = $val) {
if ($val [' count ']==0) {
Unset ($arr [$key]);
}else{
if ($val [' Avatar ']) {
$arr [$key] [' avatar '] = Cdnurl ($val [' Avatar '],true);
}
$sort [] = $val [' count '];
}
}
if (!empty ($arr)) {
Sort
Array_multisort ($sort, Sort_desc, $arr);
$list = Array_slice ($arr, 0,10);
}
return $list;
}

     Common time method Public function Invitationtime ($type, $v) {if ($type ==1) {//Today $beginToday = Mktime (0,0,0,date (' m '), D        Ate (' d '), date (' Y '));        $endToday = Mktime (0,0,0,date (' m '), date (' d ') +1,date (' Y '))-1; $where = "Superior REGEXP ' ^{$v [' id ']}_ ' and createtime between '. $beginToday."    and ". $endToday.";}        if ($type ==2) {//Yesterday $beginYesterday = Mktime (0,0,0,date (' m '), date (' d ') -1,date (' Y '));        $endYesterday = Mktime (0,0,0,date (' m '), date (' d '), date (' Y '))-1; $where = "Superior REGEXP ' ^{$v [' id ']}_ ' and createtime between '. $beginYesterday."    and ". $endYesterday.";}        if ($type ==3) {//this week $beginWeek =mktime (0,0,0,date (' m '), date (' d ')-date (' W ') +1,date (' Y '));        $endWeek =mktime (23,59,59,date (' m '), date (' d ')-date (' W ') +7,date (' Y ')); $where = "Superior REGEXP ' ^{$v [' id ']}_ ' and createtime between '. $beginWeek."    and ". $endWeek.";}        if ($type ==4) {//Last week $beginLastweek =mktime (0,0,0,date (' m '), date (' d ')-date (' W ') +1-7,date (' Y '));$endLastweek =mktime (23,59,59,date (' m '), date (' d ')-date (' W ') +7-7,date (' Y ')); $where = "Superior REGEXP ' ^{$v [' id ']}_ ' and createtime between '. $beginLastweek."    and ". $endLastweek.";}        if ($type ==5) {//this month $beginThismonth =mktime (0,0,0,date (' m '), 1,date (' Y '));        $endThismonth =mktime (23,59,59,date (' m '), date (' t '), date (' Y ')); $where = "Superior REGEXP ' ^{$v [' id ']}_ ' and createtime between '. $beginThismonth."    and ". $endThismonth.";}        if ($type ==6) {//Last month $beginLastmonth =strtotime (' y-m-01 00:00:00 ', Strtotime ('-1 month ')); $endLastmonth =strtotime (Date ("Y-m-d 23:59:59", Strtotime (-date (' d ').        Day ')); $where = "Superior REGEXP ' ^{$v [' id ']}_ ' and createtime between '. $beginLastmonth."    and ". $endLastmonth.";} return $where;}

Sort the PHP array and take the number of array bars

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.