original_string: public function sort(array $fields)
      {
          foreach (array_reverse($fields) as $key => $direction) {
              // Uses usort with a function that will access the $key and sort in
              // the $direction. It mimics how the mongodb does sorting internally.
              usort(
                  $this->items,
                  function ($a, $b) use ($key, $direction) {
                      $a = is_object($a)
                          ? ($a->$key ?? null)
                          : ($a[$key] ?? null);
  
                      $b = is_object($b)
                          ? ($b->$key ?? null)
                          : ($b[$key] ?? null);
  
                      return ($a <=> $b) * $direction;
                  }
              );
          }
  
          return $this;
      }
code: public function sort(array $fields)
      {
          foreach (array_reverse($fields) as $key => $direction) {
              // Uses usort with a function that will access the $key and sort in
              // the $direction. It mimics how the mongodb does sorting internally.
              usort(
                  $this->items,
                  function ($a, $b) use ($key, $direction) {
                      $a = is_object($a)
                          ? ($a->$key ?? null)
                          : ($a[$key] ?? null);
  
                      $b = is_object($b)
                          ? ($b->$key ?? null)
                          : ($b[$key] ?? null);
  
                      return ($a <=> $b) * $direction;
                  }
              );
          }
  
          return $this;
      }
code_tokens: public function sort ( array $ fields ) { foreach ( array_reverse ( $ fields ) as $ key => $ direction ) { // Uses usort with a function that will access the $key and sort in // the $direction. It mimics how the mongodb does sorting internally. usort ( $ this -> items , function ( $ a , $ b ) use ( $ key , $ direction ) { $ a = is_object ( $ a ) ? ( $ a -> $ key ?? null ) : ( $ a [ $ key ] ?? null ) ; $ b = is_object ( $ b ) ? ( $ b -> $ key ?? null ) : ( $ b [ $ key ] ?? null ) ; return ( $ a <=> $ b ) * $ direction ; } ) ; } return $ this ; }
docstring: Sorts the results by given fields.
  
  @param array $fields 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 EmbeddedCursor returns this cursor
docstring_tokens: Sorts the results by given fields .