MongoCursor::sort PHP Method

sort() public method

Sorts the results by given fields
public sort ( array $fields ) : MongoCursor
$fields array An array of fields by which to sort. Each element in the array has as key the field name, and as value either 1 for ascending sort, or -1 for descending sort
return MongoCursor Returns the same cursor that this method was called on
    public function sort(array $fields)
    {
        $this->errorIfOpened();
        $this->sort = $fields;
        return $this;
    }

Usage Example

 /**
  * @param \MongoCursor $cursor
  * @param ODM          $odm
  * @param string|null  $class
  * @param array        $sort
  * @param int          $limit
  * @param int          $offset
  */
 public function __construct(\MongoCursor $cursor, ODM $odm, $class, array $sort = [], $limit = null, $offset = null)
 {
     $this->cursor = $cursor;
     $this->odm = $odm;
     $this->class = $class;
     !empty($sort) && $this->cursor->sort($sort);
     !empty($limit) && $this->cursor->limit($limit);
     !empty($offset) && $this->cursor->skip($offset);
 }
All Usage Examples Of MongoCursor::sort