public function dogetfile() { global $_M; $filearray = traversal(PATH_WEB . '/upload/', 'jpg|png|gif|jpeg|bmp', '((\\/upload\\/[0-9]{6}\\/thumb)|(\\/upload\\/[0-9]{6}\\/thumb_dis)|(\\/upload\\/[0-9]{6}\\/watermark)|(\\/upload\\/thumb_src)|(\\/upload\\/files)|(\\/upload\\/images)|(\\/upload\\/_thumb))'); //_thumbs foreach ($filearray as $val) { $img_info = getimagesize(PATH_WEB . $val); $img_name = pathinfo(PATH_WEB . $val); $info['name'] = $img_name['basename']; $info['path'] = $val; $info['value'] = '..' . $val; $info['x'] = $img_info[0]; $info['y'] = $img_info[1]; $info['time'] = filemtime(PATH_WEB . $val); $array[] = $info; } $arrays = arr_sort($array, 'time', SORT_DESC); echo jsonencode($arrays); }
<?php /* Зад.6* Да се напише метод, който намира най-малък елемент в масив. Чрез този метод да се сортират елементите на масива по големина (пряка селекция, алгоритъм е онагледен тук на Select). */ function arr_sort($arr = array(5, 7, 2, 3, 1)) { // ----------- start ---------------- // ---------------- end ---------------- } $arr = array(5, 10, 11, 70, 4, 3, 2, 20, 30, 7, 50, 18, 9); arr_sort($arr);
public function testSort() { $input = range("a", "z"); $messed_up = array_reverse($input); $this->assertEquals("z", $messed_up[0]); $this->assertEquals($input, arr_sort($input)); }
function sel_product($section_value) { $restype = fetch_array("select id from " . dbtable("product_type") . " where upid='2'"); $type_id = ""; $where = ""; foreach ($restype as $key => $row) { if ($key != 0) { $type_id .= ","; } $type_id .= "'" . $row['id'] . "'"; } $where .= " tid in ({$type_id}) "; $respro = fetch_array("select stitle from " . dbtable("product") . " where " . $where . " and status=1 "); $all_pro = array(); foreach ($respro as $row) { $all_pro[] = $row['stitle']; } $result[0] = array("1" => $all_pro, "2" => array("经典A-B保背健", "经典超级保背健", "经典豪华保背健", "经典呵背", "温度智慧 I 1200", "温度智慧 I 1600", "温度智慧 II 1200", "温度智慧 II 1600", "皇家蓝宝石", "皇家红宝石", "皇家绿宝石", "皇家金钻石", "皇家皇冠", "传家宝", "帝冠"), "3" => array("满天星", "彩虹桥"), "4" => array("经典薄款保背健", "经典保背健", "经典A-B保背健", "经典超级保背健", "经典豪华保背健", "温度智慧 I 1200")); $result[1] = array("1" => array("满天星", "彩虹桥"), "2" => array("满天星", "彩虹桥"), "3" => array("经典超级保背健", "经典豪华保背健", "经典呵背", "温度智慧 I 1600", "温度智慧 II 1600", "皇家红宝石", "皇家金钻石"), "4" => array("经典超级保背健", "经典豪华保背健", "经典呵背", "温度智慧 I 1600", "温度智慧 II 1600", "皇家金钻石", "皇家皇冠", "传家宝", "帝冠"), "5" => array("经典A-B保背健", "经典超级保背健", "经典豪华保背健", "温度智慧 I 1200", "温度智慧 II 1200", "皇家蓝宝石", "皇家红宝石", "皇家绿宝石", "皇家皇冠", "帝冠"), "6" => array("经典薄款保背健", "经典保背健", "经典A-B保背健", "温度智慧 I 1200", "温度智慧 II 1200", "皇家蓝宝石", "皇家红宝石", "皇家绿宝石"), "7" => array("经典薄款保背健", "经典保背健", "经典A-B保背健", "温度智慧 I 1200", "温度智慧 II 1200", "皇家蓝宝石", "皇家红宝石", "皇家绿宝石"), "8" => array("经典薄款保背健", "经典保背健", "经典A-B保背健", "温度智慧 I 1200", "温度智慧 II 1200", "皇家蓝宝石", "皇家红宝石", "皇家绿宝石")); $result[2] = array("1" => array("经典超级保背健", "经典呵背", "温度智慧 I 1600", "温度智慧 II 1600", "皇家金钻石", "皇家皇冠", "传家宝"), "2" => $all_pro, "3" => $all_pro, "4" => array("经典A-B保背健", "经典豪华保背健", "温度智慧 I 1200", "温度智慧 II 1200", "皇家蓝宝石", "皇家红宝石", "皇家绿宝石", "帝冠")); $result[3] = array("1" => array("经典超级保背健", "经典呵背", "温度智慧 I 1600", "温度智慧 II 1600", "皇家金钻石", "传家宝"), "2" => array("温度智慧 II 1600", "皇家金钻石", "传家宝"), "3" => array("经典薄款保背健", "经典保背健", "经典A-B保背健", "温度智慧 I 1200", "温度智慧 II 1200", "皇家蓝宝石", "皇家绿宝石"), "4" => array("经典超级保背健", "经典呵背", "温度智慧 I 1600", "温度智慧 II 1600", "皇家皇冠", "皇家红宝石"), "5" => array("经典A-B保背健", "经典豪华保背健", "温度智慧 I 1200", "温度智慧 II 1200", "皇家红宝石", "帝冠")); $result[4] = array("1" => $all_pro, "2" => array("经典豪华保背健", "经典呵背", "温度智慧 I 1600", "温度智慧 II 1600", "皇家金钻石", "皇家皇冠", "传家宝"), "3" => $all_pro, "4" => array("经典呵背", "温度智慧 II 1600", "皇家皇冠", "帝冠")); $result[5] = array("1" => array("经典豪华保背健", "经典呵背", "温度智慧 II 1600", "皇家红宝石", "皇家皇冠", "帝冠"), "2" => array("经典A-B保背健", "经典豪华保背健", "温度智慧 II 1200", "皇家蓝宝石", "皇家红宝石", "皇家皇冠"), "3" => array("温度智慧 I 1200", "温度智慧 I 1600", "温度智慧 II 1200", "温度智慧 II 1600"), "4" => array("经典豪华保背健", "经典呵背", "温度智慧 I 1200", "温度智慧 I 1600", "温度智慧 II 1200", "温度智慧 II 1600", "皇家蓝宝石", "皇家红宝石", "皇家绿宝石", "皇家金钻石", "皇家皇冠", "传家宝", "帝冠"), "5" => array("温度智慧 I 1200", "温度智慧 I 1600", "温度智慧 II 1200", "温度智慧 II 1600", "皇家蓝宝石", "皇家红宝石", "皇家绿宝石", "皇家皇冠", "传家宝", "帝冠")); $sel_value = explode(",", $section_value); // $re_result=$all_pro; $re_result = array(); for ($i = 0; $i < count($sel_value); $i++) { $sel_result = $sel_value[$i]; if ($sel_value[0] == "3" or count($sel_value) > 1 and ($sel_value[1] == "1" or $sel_value[1] == "2")) { $re_value = array("status" => 2, "data" => '"满天星","彩虹桥"'); return $re_value; } else { $re_result = array_merge($re_result, $result[$i][$sel_result]); // $re_result=arr_re($re_result,$result[$i][$sel_result]); // if($result[$i][$sel_result]=="all") // { // $re_value=array( // "status"=>1 // ); // return $re_value; // }else{ // } } } $array1 = array_count_values($re_result); $re_sort = arr_sort($array1); $re_char = arr_char($re_sort); $re_value = array("status" => 2, "data" => $re_char); return $re_value; }
public function mymsg() { if (session('userid')) { $userid = session('userid'); $group_db = M('Group'); $groupuser_db = M('Groupuser'); $groupinvit = M('Groupinvit'); $groupmsg_db = M('Groupmsg'); $message_db = M('Message'); $sysmsg_db = M('Sysmsg'); $user_db = M('Users'); $friend_db = M('Friend'); //好友消息 $flist = $user_db->table(C('DB_PREFIX') . 'Users U')->join(C('DB_PREFIX') . 'Friend F on U.userid = F.fuserid')->field('U.userid,U.nickname,U.photo,F.ftime as ftime,F.status as fstatus')->where("F.userid = {$userid}")->select(); $fwdccount = 0; foreach ($flist as $key => $val) { if ($val['fstatus'] == '1') { $fmap = array(); $fmap['fuserid'] = $val['userid']; $fmap['tuserid'] = $userid; $lasttime = $message_db->where($fmap)->field('stime,content')->order('stime desc')->find(); $fmap['isread'] = '0'; $fwdcount = $message_db->where($fmap)->count(); $flist[$key]['lstime'] = $lasttime['stime']; $flist[$key]['fwdcount'] = $fwdcount; $flist[$key]['lastmsg'] = $lasttime['content']; } else { $fwdcount = '1'; $flist[$key]['lstime'] = $val['ftime']; $flist[$key]['fwdcount'] = $fwdcount; $flist[$key]['lastmsg'] = "您有一条新的好友请求"; } $fwdccount = $fwdccount + $fwdcount; } $flist = arr_sort($flist, 'lstime', 'desc'); $this->assign('fwdccount', $fwdccount); $this->assign('flist', $flist); //群组消息 $mglist = $group_db->table(C('DB_PREFIX') . 'Group G')->join(C('DB_PREFIX') . 'Groupuser GU on G.id = GU.groupid')->where("GU.userid = {$userid} and G.status = 1")->select(); $gwdccount = 0; foreach ($mglist as $k => $v) { $gmmap['groupid'] = $v['id']; $gumap['groupid'] = $v['id']; $gumap['userid'] = session('userid'); $time = $groupuser_db->where($gumap)->find(); if ($time['status'] == '1') { $gcmap['groupid'] = $v['id']; $gcmap['stime'] = array('gt', $time['lasttime']); $wdcount = $groupmsg_db->where($gcmap)->count(); $lastmsg = $groupmsg_db->where($gmmap)->order('stime desc')->find(); $mglist[$k]['lasttime'] = $lastmsg['stime']; $mglist[$k]['lastmsg'] = $lastmsg['msg']; $mglist[$k]['wdcount'] = $wdcount; } else { $mglist[$k]['lasttime'] = $time['lasttime']; $mglist[$k]['lastmsg'] = "您有一个新的群邀请待处理。"; $wdcount = '1'; $mglist[$k]['wdcount'] = $wdcount; } $gwdccount = $gwdccount + $wdcount; } $mglist = arr_sort($mglist, 'lasttime', 'desc'); $this->assign('gwdccount', $gwdccount); $this->assign('mglist', $mglist); //系统信息管理(群邀请,好友申请,提示信息) //订单消息 $ordmap['stype'] = '2'; $ordmap['uid'] = $userid; $sysorder = $sysmsg_db->where($ordmap)->select(); $ordmap['status'] = '0'; $sysordercount = $sysmsg_db->where($ordmap)->count(); $this->assign('sysordercount', $sysordercount); $this->assign('sysorder', $sysorder); //换驾消息 $hjmap['stype'] = '1'; $hjmap['uid'] = $userid; $syshj = $sysmsg_db->where($hjmap)->select(); $hjmap['status'] = '0'; $syshjcount = $sysmsg_db->where($hjmap)->count(); $this->assign('syshjcount', $syshjcount); $this->assign('syshj', $syshj); //系统消息 $sysmap['stype'] = '0'; $sysmap['uid'] = $userid; $syslist = $sysmsg_db->where($sysmap)->select(); $sysmap['status'] = '0'; $syscount = $sysmsg_db->where($sysmap)->count(); $this->assign('syscount', $syscount); $this->assign('syslist', $syslist); /* * Kaijin添加 */ if (I('get.xiaoxi')) { $xiaoxi = I('get.xiaoxi'); } else { $xiaoxi = ''; } //var_dump($xiaoxi);die(); $this->assign('xiaoxi', $xiaoxi); /* * Kaijin添加结束 */ /* $map['userid'] = session('userid'); $map['status'] = 0; $giinfo = $groupuser_db->where($map)->select(); $mfmap['fuserid'] = session('userid'); $mfmap['status'] = 0; $fulist = $friend_db->where($mfmap)->select(); */ $this->display(); } else { $this->redirect('User/login'); } }