コード例 #1
0
ファイル: collection.php プロジェクト: nsteiner/kdoc
 /**
  * Sorts the collection by any number of fields
  *
  * @return  Collection
  */
 public function sortBy()
 {
     $args = func_get_args();
     $collection = clone $this;
     $array = $collection->data;
     $params = array();
     if (empty($array)) {
         return $collection;
     }
     foreach ($args as $i => $param) {
         if (is_string($param)) {
             if (strtolower($param) === 'desc') {
                 ${"param_{$i}"} = SORT_DESC;
             } else {
                 if (strtolower($param) === 'asc') {
                     ${"param_{$i}"} = SORT_ASC;
                 } else {
                     ${"param_{$i}"} = array();
                     foreach ($array as $index => $row) {
                         ${"param_{$i}"}[$index] = str::ascii(is_array($row) ? str::lower($row[$param]) : str::lower($row->{$param}()));
                     }
                 }
             }
         } else {
             ${"param_{$i}"} = $args[$i];
         }
         $params[] =& ${"param_{$i}"};
     }
     $params[] =& $array;
     call_user_func_array('array_multisort', $params);
     $collection->data = $array;
     return $collection;
 }