sort() static public method

Sorts a multi-dimensional array by a certain column
static public sort ( array $array, string $field, string $direction = 'desc', const $method = SORT_REGULAR ) : array
$array array The source array
$field string The name of the column
$direction string desc (descending) or asc (ascending)
$method const A PHP sort method flag.
return array The sorted array
コード例 #1
0
ファイル: tagcloud.php プロジェクト: niklausgerber/themis
function tagcloud($parent, $options = array())
{
    global $site;
    // default values
    $defaults = array('limit' => false, 'field' => 'tags', 'children' => 'visible', 'baseurl' => $parent->url(), 'param' => 'tag', 'sort' => 'name', 'sortdir' => 'asc');
    // merge defaults and options
    $options = array_merge($defaults, $options);
    switch ($options['children']) {
        case 'invisible':
            $children = $parent->children()->invisible();
            break;
        case 'visible':
            $children = $parent->children()->visible();
            break;
        default:
            $children = $parent->children();
            break;
    }
    $cloud = array();
    foreach ($children as $p) {
        $tags = str::split($p->{$options}['field']());
        foreach ($tags as $t) {
            if (isset($cloud[$t])) {
                $cloud[$t]->results++;
            } else {
                $cloud[$t] = new obj(array('results' => 1, 'name' => $t, 'url' => $options['baseurl'] . '/' . $options['param'] . ':' . $t, 'isActive' => param($options['param']) == $t ? true : false));
            }
        }
    }
    $cloud = a::sort($cloud, $options['sort'], $options['sortdir']);
    if ($options['limit']) {
        $cloud = array_slice($cloud, 0, $options['limit']);
    }
    return $cloud;
}
コード例 #2
0
ファイル: ATest.php プロジェクト: LucasFyl/korakia
 public function testSort()
 {
     $users = $this->users;
     $users = a::sort($users, 'username', 'asc');
     $first = a::first($users);
     $last = a::last($users);
     $this->assertEquals('mary', $first['username']);
     $this->assertEquals('peter', $last['username']);
 }
コード例 #3
0
ファイル: pages.php プロジェクト: robeam/kirbycms
 function sortBy($field, $direction = 'asc')
 {
     $pages = a::sort($this->_, $field . ' ' . $direction);
     return new pages($pages);
 }
コード例 #4
0
ファイル: files.php プロジェクト: nilshendriks/kirbycms
 function sortBy($field, $direction = 'asc', $method = SORT_REGULAR)
 {
     $files = a::sort($this->_, $field, $direction, $method);
     return new files($files);
 }
コード例 #5
0
ファイル: pages.php プロジェクト: ajmalafif/bradshawsguide
 function sortBy($field, $direction = 'asc', $method = SORT_REGULAR)
 {
     if ($field == 'dirname') {
         $method = 'natural';
     }
     $pages = a::sort($this->_, $field, $direction, $method);
     return new pages($pages);
 }
コード例 #6
0
ファイル: docs.languages.php プロジェクト: rugk/getkirby.com
?>

<main class="main" role="main">

  <div class="col-4-6 last">

    <article class="text">
      <h1><?php 
echo html($page->title());
?>
</h1>

      <h2>Available Translations</h2>
      <dl>
        <?php 
$langs = a::sort(yaml($page->languages()), 'lang', 'asc');
?>
        <?php 
foreach ($langs as $lang) {
    ?>
        <dt class="gamma"><a href="https://github.com/getkirby/panel/blob/master/app/languages/<?php 
    echo $lang['code'];
    ?>
.php"><?php 
    echo $lang['lang'];
    ?>
</a></dt>
        <dd><span>Author: </span><?php 
    echo $lang['author'];
    ?>
</dd>