sort() 공개 메소드

Sort a multi-dimensional array variable on a specified column
public sort ( array &$var, $col, $order = SORT_ASC ) : boolean
$var array array
$col mixed
$order int
리턴 boolean
예제 #1
0
 /**
 		Return an array of objects matching criteria
 			@return array
 			@param $cond array
 			@param $seq array
 			@param $limit mixed
 			@param $ofs int
 			@param $jig boolean
 			@public
 	**/
 function find(array $cond = NULL, array $seq = NULL, $limit = 0, $ofs = 0, $jig = TRUE)
 {
     $table = $this->db->read($this->table);
     $result = array();
     if ($table) {
         if (is_array($seq)) {
             foreach (array_reverse($seq, TRUE) as $key => $sort) {
                 Matrix::sort($table, $key, $sort);
             }
         }
         foreach ($table as $key => $obj) {
             $obj['_id'] = $key;
             if (is_null($cond) || $this->check($cond, $obj)) {
                 $result[] = $jig ? $this->factory($obj) : $obj;
             }
         }
         $result = array_slice($result, $ofs, $limit ?: NULL);
     }
     $this->db->result = $result;
     return $result;
 }
예제 #2
0
파일: main.php 프로젝트: nian2go/fatfree
 function matrix()
 {
     $this->set('title', 'Matrix');
     $this->expect(is_null($this->get('ERROR')), 'No errors expected at this point', 'ERROR variable is set: ' . $this->get('ERROR.text'));
     $z = array(array('id' => 123, 'name' => 'paul', 'sales' => 0.35), array('id' => 456, 'name' => 'ringo', 'sales' => 0.13), array('id' => 345, 'name' => 'george', 'sales' => 0.57), array('id' => 234, 'name' => 'john', 'sales' => 0.79));
     Matrix::sort($z, 'name');
     $this->expect(array_values($z) == array(array('id' => 345, 'name' => 'george', 'sales' => 0.57), array('id' => 234, 'name' => 'john', 'sales' => 0.79), array('id' => 123, 'name' => 'paul', 'sales' => 0.35), array('id' => 456, 'name' => 'ringo', 'sales' => 0.13)), 'Sorting a multi-dimensional array by string column works properly', 'Incorrect array sort algorithm: ' . var_export($z, TRUE));
     Matrix::sort($z, 'id');
     $this->expect(array_values($z) == array(array('id' => 123, 'name' => 'paul', 'sales' => 0.35), array('id' => 234, 'name' => 'john', 'sales' => 0.79), array('id' => 345, 'name' => 'george', 'sales' => 0.57), array('id' => 456, 'name' => 'ringo', 'sales' => 0.13)), 'Sorting a multi-dimensional array by integer column works properly', 'Incorrect array sort algorithm: ' . var_export($z, TRUE));
     Matrix::sort($z, 'sales');
     $this->expect(array_values($z) == array(array('id' => 456, 'name' => 'ringo', 'sales' => 0.13), array('id' => 123, 'name' => 'paul', 'sales' => 0.35), array('id' => 345, 'name' => 'george', 'sales' => 0.57), array('id' => 234, 'name' => 'john', 'sales' => 0.79)), 'Sorting a multi-dimensional array by float column works properly', 'Incorrect array sort algorithm: ' . var_export($z, TRUE));
     echo $this->render('basic/results.htm');
 }