public function sort(array $sorted_columns): self
    {
        $diff = array_diff_assoc($sorted_columns, array_unique($sorted_columns));
        if (count($diff) > 0) {
            $cols = implode(',', $diff);
            throw new Exception\DuplicateColumnException(__METHOD__ . " Duplicate column found in paramter sorted_columns : '$cols'");
        }
        $columns = [];

        foreach ($sorted_columns as $idx => $column) {
            if (!$this->exists($column)) {
                throw new Exception\InvalidArgumentException(__METHOD__ . " Column '$column' does not exists.");
            }
            $columns[$column] = $this->get($column);
        }
        // Appending eventual non sorted columns at the end
        $columns = array_merge($columns, (array) $this->columns);
        $this->columns->exchangeArray($columns);

        return $this;
    }
public function sort(array $sorted_columns): self
    {
        $diff = array_diff_assoc($sorted_columns, array_unique($sorted_columns));
        if (count($diff) > 0) {
            $cols = implode(',', $diff);
            throw new Exception\DuplicateColumnException(__METHOD__ . " Duplicate column found in paramter sorted_columns : '$cols'");
        }
        $columns = [];

        foreach ($sorted_columns as $idx => $column) {
            if (!$this->exists($column)) {
                throw new Exception\InvalidArgumentException(__METHOD__ . " Column '$column' does not exists.");
            }
            $columns[$column] = $this->get($column);
        }
        // Appending eventual non sorted columns at the end
        $columns = array_merge($columns, (array) $this->columns);
        $this->columns->exchangeArray($columns);

        return $this;
    }
public function sort ( array $ sorted_columns ) : self { $ diff = array_diff_assoc ( $ sorted_columns , array_unique ( $ sorted_columns ) ) ; if ( count ( $ diff ) > 0 ) { $ cols = implode ( ',' , $ diff ) ; throw new Exception \ DuplicateColumnException ( __METHOD__ . " Duplicate column found in paramter sorted_columns : '$cols'" ) ; } $ columns = [ ] ; foreach ( $ sorted_columns as $ idx => $ column ) { if ( ! $ this -> exists ( $ column ) ) { throw new Exception \ InvalidArgumentException ( __METHOD__ . " Column '$column' does not exists." ) ; } $ columns [ $ column ] = $ this -> get ( $ column ) ; } // Appending eventual non sorted columns at the end $ columns = array_merge ( $ columns , ( array ) $ this -> columns ) ; $ this -> columns -> exchangeArray ( $ columns ) ; return $ this ; }
Sort columns in the order specified, columns that exists
in the dataset but not in the sorted_columns will be
appended to the end.

@param string[] $sorted_columns
Sort columns in the order specified columns that exists in the dataset but not in the sorted_columns will be appended to the end .