Exemplo n.º 1
0
function sortResult($mysqli, $isPagination = false, $columnValues = array(), $result = array())
{
    if (isset($_GET['orderBy'])) {
        $orderBy = clearData($_GET['orderBy'], $mysqli);
        if ($orderBy != "") {
            list($column, $sortAscDesc) = explode(" ", $orderBy);
            foreach ($columnValues as $value) {
                if ($value == $column) {
                    $data['form']['orderBy']['sortAscDesc'] = $sortAscDesc;
                    $data['form']['orderBy']['column'] = $column;
                    if ($isPagination === false) {
                        $data['result'] = sortArray($result, $column, $sortAscDesc);
                    } else {
                        //$sortAscDesc == "ASC" ? $sortAscDesc = "DESC" : $sortAscDesc = "ASC";
                        $data['result'] = " ORDER BY ISNULL({$column}), {$column} {$sortAscDesc} ";
                    }
                    return $data;
                }
            }
        }
    }
    if ($isPagination === false) {
        $data['result'] = $result;
    } else {
        $data['result'] = "";
    }
    return $data;
}
Exemplo n.º 2
0
 /**
  * 构造函数,父类
  * @Title: __construct
  * @Description: todo(基础构造函数)
  *
  * @author quqiang
  *         @date 2015年5月12日 下午4:37:55
  * @throws
  *
  */
 public function __construct()
 {
     parent::__construct();
     // 加载基础配置信息
     $dir = CONF_PATH;
     $configDir = $dir . 'desing.php';
     if (!file_exists($configDir)) {
         $msg = '文件 ' . $configDir . ' 不存在!';
         throw new NullDataExcetion($msg);
     }
     require $configDir;
     $this->default = $desing_default;
     $this->controls = $desing_controll;
     // 合并组件配置元素
     if ($this->controls && $this->default) {
         unset($temp);
         foreach ($this->controls as $k => $v) {
             $array = array_merge($this->default, $v['property']);
             sortArray($array, 'sort');
             $temp[$k] = $array;
         }
         $this->controlsConfig = $temp;
     }
     $this->assign('config', $this->controlsConfig);
     $this->assign('control', $this->controls);
     $this->assign('tagIndentity', $this->tagIndentity);
     $this->assign('propertyTagType', $this->propertyTagType);
 }
Exemplo n.º 3
0
 /**
  * 列出目录的文件列表
  * @path 路径
  * @sortBy 排序方式(默认,文件名称,更新时间)
  */
 public static function listFiles($path, $orderBy = NULL, $orderType = "SORT_ASC")
 {
     if (is_dir($path) == false) {
         return NULL;
     }
     $handle = opendir($path);
     if ($handle == false) {
         return NULL;
     }
     $fileList = array();
     while (false != ($file = readdir($handle))) {
         if ($file == '.' || $file == '..') {
             continue;
         }
         $fileInfo['Name'] = $file;
         $fileInfo['IsDir'] = is_dir($path . $file);
         $fileInfo['Modified'] = filemtime($path . $file);
         $fileList[] = $fileInfo;
     }
     closedir($handle);
     if ($orderBy == "Name") {
         $fileList = sortArray($fileList, "Name", $orderType);
     } else {
         if ($orderBy == "Modified") {
             $fileList = sortArray($fileList, "Modified", $orderType);
         }
     }
     return $fileList;
 }
 /**
  * 显示当前面板内容
  * @Title: showPanel
  * @Description: todo(页面展示)
  * @author 管理员
  * @date 2015-06-30 19:36:36
  * @throws
  */
 public function showPanel()
 {
     import('@.ORG.Browse');
     $submodel = M("mis_system_panel_desing_sub");
     $sublist = $submodel->where("masid=15")->select();
     $scdmodel = D("SystemConfigDetail");
     $map["status"] = 1;
     foreach ($sublist as $key => $val) {
         $model = $val["modelname"];
         $fields = explode(",", $val["showtitle"]);
         $defaultwidth = (int) 100 / count($fields);
         $temp = explode(",", $val["showtitle"]);
         foreach ($temp as $tk => $tv) {
             $temparr = explode("|", $tv);
             if ($temparr[2]) {
                 $fields[$temparr[0]]['name'] = $temparr[0];
                 $fields[$temparr[0]]['width'] = $temparr[1];
                 $fields[$temparr[0]]['sort'] = $temparr[2];
             }
         }
         sortArray($fields, 'sort', 'asc', 'number');
         $detailList = $scdmodel->getDetail($model, true, "", "status");
         $sublist[$key]['link'] = __APP__ . "/" . $model . "/index";
         $sublist[$key]['rel'] = $model;
         $newd = array();
         foreach ($fields as $k => $v) {
             foreach ($detailList as $dk => $dv) {
                 if ($v['name'] == $dv['name']) {
                     $newd[$k] = $dv;
                     $newd[$k]['shows'] = 1;
                     $newd[$k]['sortnum'] = $v['sort'];
                     if (strpos('px', $v['width']) > 0 || strpos('PX', $v['width']) > 0 || strpos('Px', $v['width']) > 0) {
                         $newd[$k]['widths'] = $v['width'];
                     } else {
                         $newd[$k]['widths'] = $v['width'] ? $v['width'] . "%" : $defaultwidth . "%";
                     }
                 }
             }
         }
         $sublist[$key]["detailList"] = $newd;
         //具体数据1
         $listmodel = D($model);
         $val['num'] = $val['num'] ? $val['num'] : 5;
         //获取当前模型数据权限 by renl 20150626
         $broMap = Browse::getUserMap($model);
         if ($broMap) {
             if ($map['_string']) {
                 $map['_string'] .= " and " . $broMap;
             } else {
                 $map['_string'] = $broMap;
             }
         }
         $list = $listmodel->where($map)->order('id desc')->limit($val['num'])->select();
         $sublist[$key]["list"] = $list;
         unset($map["_string"]);
     }
     $this->assign("sublist", $sublist);
     $this->display("MisSystemPanelDesingMas:news");
 }
Exemplo n.º 5
0
function printArray()
{
    $sortedArray = sortArray();
    $count = count($sortedArray);
    for ($i = 0; $i < $count; $i++) {
        for ($j = 0; $j < count($sortedArray[$i]); $j++) {
            echo $sortedArray[$i][$j] . " ";
        }
        echo "Summ = " . getSumArray($sortedArray[$i]) . "<hr>";
    }
}
Exemplo n.º 6
0
 /**
  * 获取等级排行列表
  * @access private
  * @param string $fid 贴吧id
  * @return array
  */
 private function getLevelRankList($fid)
 {
     $member_list_array = $this->getMemberList($fid);
     $info = $member_list_array[0];
     foreach ($info as $key => $value) {
         $info[$key]['exp'] = A('Home')->getExp($info[$key]['fans_id'], $info[$key]['forum_id']);
         $info[$key]['level'] = A('Home')->getLevel($info[$key]['fans_id'], $info[$key]['forum_id']);
     }
     $res = sortArray($info, 'exp', 'desc');
     return $res;
 }
Exemplo n.º 7
0
function getNearObjectsForId($connection, $lat, $lon, $tags, $maxdistance)
{
    // combine tags to one request
    $command = array();
    $objects = array();
    $tagcount = count($tags);
    // construct query from array
    for ($i = 0; $i < $tagcount - 1; $i++) {
        $tagquery .= "tags-> '" . $tags[$i][0] . "' = '" . $tags[$i][1] . "' OR ";
    }
    $tagquery .= "tags-> '" . $tags[$i][0] . "' = '" . $tags[$i][1] . "'";
    // first select next objects ordered by distance, then throw out multiple names, then reorder by distance and limit on 2 objects
    $query = "\n\t\t\tSELECT *\n\t\t\tFROM (\n\t\t\t\tSELECT DISTINCT ON (uniques.name) *\n\t\t\t\tFROM (\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tST_X(foo.next),\n\t\t\t\t\t\tST_Y(foo.next),\n\t\t\t\t\t\tfoo.name,\n\t\t\t\t\t\tfoo.distance,\n\t\t\t\t\t\tfoo.osmid\n\t\t\t\t\tFROM (\n\t\t\t\t\t\t(SELECT tags->'name' AS name, geom AS next, id AS osmid,  ST_Distance_Sphere(GeometryFromText('POINT ( " . $lat . " " . $lon . " )', 4326 ), geom) AS distance\n\t\t\t\t\t\tFROM nodes\n\t\t\t\t\t\tWHERE (" . $tagquery . ") AND (NOT (tags ? 'disused')) AND ((NOT (tags ? 'access')) OR (tags->'access' = 'customers') OR (tags->'access' = 'permissive') OR (tags->'access' = 'yes') OR (tags->'access' = 'public') OR (tags->'access' = 'destination')) AND geom && ST_Buffer(GeometryFromText('POINT ( " . $lat . " " . $lon . " )', 4326 ), 2000)\n\t\t\t\t\t\tORDER BY distance\n\t\t\t\t\t\tLIMIT 10)\n\t\t\t\t\t\tUNION\n\t\t\t\t\t\t(SELECT tags->'name' AS name, geom AS next, id AS osmid,  ST_Distance_Sphere(GeometryFromText('POINT ( " . $lat . " " . $lon . " )', 4326 ), geom) AS distance\n\t\t\t\t\t\tFROM ways\n\t\t\t\t\t\tWHERE (" . $tagquery . ") AND (NOT (tags ? 'disused')) AND ((NOT (tags ? 'access')) OR (tags->'access' = 'customers') OR (tags->'access' = 'permissive') OR (tags->'access' = 'yes') OR (tags->'access' = 'public') OR (tags->'access' = 'destination')) AND geom && ST_Buffer(GeometryFromText('POINT ( " . $lat . " " . $lon . " )', 4326 ), 2000)\n\t\t\t\t\t\tORDER BY distance\n\t\t\t\t\t\tLIMIT 10)\n\t\t\t\t\t) AS foo\n\t\t\t\t\tWHERE foo.distance < " . $maxdistance . "\n\t\t\t\t\tORDER BY foo.distance\n\t\t\t\t\tLIMIT 10\n\t\t\t\t) AS uniques\n\t\t\t\tORDER BY uniques.name, uniques.distance\n\t\t\t) AS ordered\n\t\t\tORDER BY ordered.distance\n\t\t\tLIMIT 2;";
    $result = pg_query($connection, $query);
    $response = pg_fetch_all($result);
    if ($response) {
        foreach ($response as $element) {
            $data[0] = $element['st_x'];
            $data[1] = $element['st_y'];
            $data[2] = $element['name'];
            $data[3] = $element['distance'];
            $data[4] = $element['osmid'];
            array_push($objects, $data);
        }
    }
    if (count($types) > 1 || count($tags) > 1) {
        return sortArray($objects);
    }
    return $objects;
}
Exemplo n.º 8
0

 <?php 
//Ottengo i valori relativi ai campi di descrizione
$args = array('post_type' => 'baa_supports', 'posts_per_page' => -1, 'tax_query' => array(array('taxonomy' => 'support_type', 'field' => 'slug', 'terms' => 'support-partner')));
$fields = get_posts($args);
$partners = array();
foreach ($fields as $field) {
    $partner = array();
    $partner['image'] = wp_get_attachment_url(get_post_thumbnail_id($field->ID));
    $partner['ordine'] = get_post_meta($field->ID, 'ordine', true);
    array_push($partners, $partner);
}
//ordino l'array
if (count($partners) > 0) {
    $partners = sortArray($partners, 'ordine', SORT_ASC);
}
//ottengo il contenuto
$support = get_post($pageID);
$args = array('post_type' => 'baa_supports', 'posts_per_page' => -1, 'tax_query' => array(array('taxonomy' => 'support_type', 'field' => 'slug', 'terms' => 'collab-detail')));
$fields = get_posts($args);
$collabs = array();
foreach ($fields as $field) {
    $collab = array();
    $collab['image'] = wp_get_attachment_url(get_post_thumbnail_id($field->ID));
    $collab['url'] = get_post_meta($field->ID, 'url', true);
    array_push($collabs, $collab);
}
?>
        <div id="inside" class="support">             
                      
 /**
  * 
  * @param importDataGetDetail 导入获取list信息
  *@param  $modelname 模型名
  * @param unknown_type $type 类型 1:list.inc 2:datatable.inc(内嵌表的inc)
  * @param unknown_type $typename list.inc.php(默认) view:MisAutoXzhheSubDatatable9.inc.php
  * @param unknown_type $listCongfigControl
  * @param unknown_type $ismore
  * @return number
  */
 public function importDataGetDetail($modelname = '', $type = '1', $typename = '', $listCongfigControl = "shows", $ismore = false)
 {
     if ($type == '1') {
         $listInfo = (require $this->GetDetailFile($modelname, false, $typename, $listCongfigControl));
     } else {
         $listInfo = (require $this->GetDetailFile($modelname, false, $typename = 'SubDatatable', $listCongfigControl, $type));
     }
     sortArray($listInfo, 'sortnum', 'asc');
     $listInfo1 = array();
     $listInfo2 = array();
     foreach ($listInfo as $lk => $lv) {
         if ($lv['shows'] == 1) {
             $listInfo1[] = $lv;
         } else {
             $listInfo2[] = $lv;
         }
     }
     $listInfo = array_merge($listInfo1, $listInfo2);
     foreach ($listInfo as $infok => $infov) {
         if ($infov['name'] != 'id' && $infov['fieldcategory'] != 'datatable') {
             $list[$infok]['name'] = $infov['name'];
             $list[$infok]['showname'] = $infov['showname'];
             $list[$infok]['transform'] = $infov['transform'];
             //是否转换 0否 1转换
             $list[$infok]['unique'] = $infov['unique'];
             //是否唯一  0否 1唯一
             $list[$infok]['validate'] = $infov['validate'];
             //验证类型
             if ($infov['required'] == '1') {
                 $required = 1;
             } else {
                 $required = 0;
             }
             $list[$infok]['required'] = $required;
             //是否必填   0否 1必填
             $list[$infok]['unfunc'] = $infov['unfunc'];
             //转换函数
             $list[$infok]['unfuncdata'] = $infov['unfuncdata'];
             //转换数据
         }
     }
     return $list;
 }
Exemplo n.º 10
0
<?php

if (!isset($argv)) {
    exit('The script must be run from the command line');
}
print 'Please provide an array of numbers: ';
$values = fgets(STDIN);
function sortArray($array)
{
    $integer = array_map('floatval', explode(', ', $array));
    $arrayValues = array_values(array_filter($integer, 'is_numeric'));
    $container = [];
    foreach ($arrayValues as $value) {
        if ($value == 0) {
            exit('You must only use number.');
        }
        $container[] = $value;
    }
    asort($container);
    print_r($container);
}
echo 'The values are sorted in ascending order' . sortArray($values);
Exemplo n.º 11
0
    }
    echo '</table>';
}
multiplicationTable(4, 4);
/* ------------------- Home 5 ---------------------- */
echo '<p>-------- Fifth exercise -------</p>';
function sortArray($arr)
{
    sort($arr);
    $sortArray = [];
    for ($i = 0; $i < count($arr); $i++) {
        $sortArray[$i] = $arr[$i];
    }
    return $sortArray;
}
$arr = sortArray(array('4', '2', '6', '3'));
print_r($arr);
/* ------------------- Home 6 ---------------------- */
echo '<p>-------- Sixth exercise -------</p>';
function getOddNumber($a, $b)
{
    if ($a > $b) {
        return;
    }
    if ($a % 2 == 1) {
        echo $a;
    }
    $a++;
    getOddNumber($a, $b);
}
getOddNumber(5, 20);
Exemplo n.º 12
0
        } else {
            if ($tab == "invite") {
                $inGroup = false;
                for ($x = 0; $x < count($members); $x++) {
                    if ($members[$x]['idBenutzer'] == $user_id) {
                        $inGroup = true;
                        break;
                    }
                }
                if ($inGroup) {
                    $sql = "CALL sps_getOwnFriends({$user_id})";
                    $result = mysql_query($sql);
                    while ($row = mysql_fetch_array($result)) {
                        $friends[] = $row;
                    }
                    $friends = sortArray($friends, "Vorname");
                    $output .= '			<tr>
										<td colspan=3 class="infounderlined">Freunde</td>
									</tr>';
                    for ($i = 0; $i < count($friends); $i++) {
                        $output .= '		<tr>
										<td style="width:60px;">
											<a href="' . $_SERVER['PHP_SELF'] . '?site=profil&id=' . $friends[$i]["idFriend"] . '">
												<img src="' . getImageSmall($friends[$i]["idFriend"]) . '" border=0></img>
											</a>
										</td>
										<td class="profilName">
											<a href="' . $_SERVER['PHP_SELF'] . '?site=profil&id=' . $friends[$i]["idFriend"] . '">
												' . $friends[$i]['Vorname'] . ' ' . $friends[$i]['Nachname'] . '
											</a>
										</td>
Exemplo n.º 13
0
<div id="menu">
    <h1><a href="http://localhost:8888/Gits/notes/">Martin Campillo</a></h1>
    <p>Carnet de notes, travaux en cours et reflexions diverses.</p>
    
    
<?php 
require_once "./php/functions.php";
$root = "./content/";
displayArray(sortArray(createArray($root), "date"));
?>
  
    <div id="footer">
        <div class="colorSwitch night">  
          <input type="checkbox" id="colorSwitch" checked />
          <label for="colorSwitch"></label>
        </div>
        <h6>Version 0.0.1
        <br>
        <a href="https://github.com/fclmprod/notes/">github.com/fclmprod/notes/</a></h6>
    </div>
    <script src="./js/main.js"></script>
    
</div>
Exemplo n.º 14
0
<?php

require_once 'array_functions.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    if (isset($_POST['frequent'])) {
        $input = $_POST['test'];
        $duplicates = getDuplicates($input);
    } elseif (isset($_POST['reverse'])) {
        $input = $_POST['test'];
        reverse($input);
    } elseif (isset($_POST['largest'])) {
        $input = $_POST['test'];
        echo largestArray($input);
    } elseif (isset($_POST['sort'])) {
        $input = $_POST['test'];
        $input = sortArray($input);
    }
}
?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Array Test</title>
  </head>
  <body>
    <?php 
if (isset($duplicates)) {
    echo $duplicates;
}
?>
Exemplo n.º 15
0
 /**
  * 获取贴吧列表
  * @access public
  * @param string $uid 用户id
  * @param boolean $page 是否分页
  * @return array
  */
 public function getForumList($uid, $page = false)
 {
     $f = getTableName('forum');
     $ff = getTableName('forum_fans');
     $condition["{$ff}.fans_id"] = $uid;
     if ($page == true) {
         $count = M('forum_fans')->where($condition)->count();
         $Pager = new \Tieba\Library\Pager($count, 20, 'current', false);
         $show = $Pager->show();
         $info = M('forum_fans')->join("{$f} ON {$ff}.forum_id = {$f}.forum_id")->where($condition)->limit($Pager->firstRow . ',' . $Pager->listRows)->select();
     } else {
         $info = M('forum_fans')->join("{$f} ON {$ff}.forum_id = {$f}.forum_id")->where($condition)->select();
     }
     foreach ($info as $key => $value) {
         $level_array = $this->getLevel($uid, $info[$key]['forum_id']);
         $info[$key]['level_level'] = $level_array[0];
         $info[$key]['level_css'] = $level_array[1];
         $info[$key]['exp'] = $this->getExp($uid, $info[$key]['forum_id']);
         $info[$key]['manage_status'] = A('Forum')->getManageStatus($info[$key]['forum_id']);
         $info[$key]['member_title'] = A('Forum')->getMemberTitle($info[$key]['forum_id'], $info[$key]['level_level']);
         if (A('Forum')->isSigned($uid, $info[$key]['forum_id']) == true) {
             $info[$key]['sign_status'] = 'sign';
         } else {
             $info[$key]['sign_status'] = 'unsign';
         }
     }
     $res = sortArray($info, 'exp', 'desc');
     if ($page == true) {
         $array[0] = $res;
         $array[1] = $show;
         return $array;
     } else {
         return $res;
     }
 }
            $array_friends[] = $row;
        } else {
            $array_friends_open[] = $row;
        }
    }
    $members = sortArray($array_friends_open, "Nachname");
} else {
    $sql = "CALL sps_getFriends({$profil_id}, {$user_id});";
    $array_friends = array();
    $array_friends_open = array();
    $result = mysql_query($sql);
    while ($row = mysql_fetch_array($result)) {
        $array_friends[] = $row;
    }
}
$members = sortArray($array_friends, "Nachname");
$output .= '<table width="100%" cellpadding="0" cellspacing="0">';
if ($profil_id == $user_id) {
    $output .= '<tr>
		<td colspan="3" class="infounderlined">Offene Freundschaftsanfragen</td>
	</tr>';
    if (empty($array_friends_open)) {
        $output .= '<tr><td colspan="3">Keine offenen Freundschaftsanfragen vorhanden</td></tr>';
    }
    foreach ($array_friends_open as $friend) {
        $output .= renderFriendOutput($friend['idFriend'], $friend['Vorname'] . " " . $friend['Nachname'], $friend['status'] == 0 ? 1 : $friend['status']);
    }
    $style = 'style="padding-top: 20px"';
}
$output .= '<tr>
		<td colspan="3" class="infounderlined" ' . (!empty($style) ? $style : '') . '>Bestehende Freundschaften</td>
Exemplo n.º 17
0
 function getSortedProjectArray($projectArray, $sortOrder)
 {
     $projectArray = getStarredProjectArray(sortArray($projectArray, $sortOrder), $sortOrder);
     return $projectArray;
 }
Exemplo n.º 18
0
<?php

//按值排序
function sortArray($objects, $sorts)
{
    $avgs = array();
    foreach ($sorts as $key => $type) {
        $sortKey = array();
        foreach ($objects as $k => $object) {
            $sortKey[$k] = $object[$key];
        }
        $avgs[] = $sortKey;
        $avgs[] = $type;
    }
    $avgs[] =& $objects;
    print_r($avgs);
    call_user_func_array('array_multisort', $avgs);
    return $objects;
}
$demo = array(array('id' => 1, 'score' => 100, 'type' => 3), array('id' => 2, 'score' => 200, 'type' => 3), array('id' => 3, 'score' => 10, 'type' => 1));
print_r(sortArray($demo, array('score' => SORT_DESC, 'type' => SORT_ASC, 'id' => SORT_DESC)));
// vim600:ts=4 st=4 foldmethod=marker foldmarker=<<<,>>>
// vim600:syn=php commentstring=//%s