sort() публичный статический метод

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
Результат array sorted according to the comparator
Пример #1
0
 public function sort($comparator)
 {
     $this->_array = Arrays::sort($this->_array, $comparator);
     return $this;
 }
Пример #2
0
 /**
  * @test
  */
 public function shouldSortArrayByDefaultExtractor()
 {
     //given
     $array = array(1, 3, 2);
     //when
     $sorted = Arrays::sort($array, Comparator::natural());
     //then
     $this->assertEquals(array(1, 2, 3), $sorted);
 }