Ouzo\Utilities\Arrays::sort PHP Method

sort() public static method

The comparator function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second. To obtain comparator one may use Comparator class (for instance Comparator::natural() which yields ordering using comparison operators). Example: class Foo { private $value; function __construct($value) { $this->value = $value; } public function getValue() { return $this->value; } } $values = array(new Foo(1), new Foo(3), new Foo(2)); $sorted = Arrays::sort($values, Comparator::compareBy('getValue()')); Result: Array ( [0] => class Foo (1) { private $value => int(1) } [1] => class Foo (1) { private $value => int(2) } [2] => class Foo (1) { private $value => int(3) } )
public static sort ( array $array, $comparator ) : array
$array array
$comparator
return array sorted according to the comparator
    public static function sort(array $array, $comparator)
    {
        usort($array, $comparator);
        return $array;
    }

Usage Example

コード例 #1
0
ファイル: FluentArray.php プロジェクト: letsdrink/ouzo
 public function sort($comparator)
 {
     $this->_array = Arrays::sort($this->_array, $comparator);
     return $this;
 }
All Usage Examples Of Ouzo\Utilities\Arrays::sort