Exemplo n.º 1
0
 public function testCompareMulti()
 {
     $values = TestData::$fruit;
     usort($values, fn\fnCompareMulti(array(fn\fnCompareField('name'))));
     $this->assertNotEquals(TestData::$fruit, $values);
     $this->assertEquals(Sequence::make(TestData::$fruit)->pluck('name')->sort()->toValues(), array_map(fn\fnPluck('name'), $values));
     $values = array(array('name' => 'Terry', 'age' => 22), array('name' => 'Bob', 'age' => 30), array('name' => 'Ann', 'age' => 30), array('name' => 'Sam', 'age' => 19), array('name' => 'Rob', 'age' => 30), array('name' => 'Robert', 'age' => 55));
     $expected = array(array('name' => 'Robert', 'age' => 55), array('name' => 'Ann', 'age' => 30), array('name' => 'Bob', 'age' => 30), array('name' => 'Rob', 'age' => 30), array('name' => 'Terry', 'age' => 22), array('name' => 'Sam', 'age' => 19));
     usort($values, fn\fnCompareMulti(array(fn\fnCompareFieldRev('age'), fn\fnCompareField('name'))));
     $this->assertEquals($expected, $values);
 }
Exemplo n.º 2
0
/**
 * @param array[] $employees
 * @return array
 */
function exampleSortByEmployeeIdRev($employees)
{
    $employeesSortedById = Sequence::make($employees)->sort(fn\fnCompareFieldRev('employeeId'))->to_a();
    return $employeesSortedById;
}
Exemplo n.º 3
0
 /**
  * Generates a comparison function that can be used to sort an array by a given field in reverse order.
  *
  * @param string $fieldName
  * @return Closure
  */
 public static function fnByFieldRev($fieldName)
 {
     return fn\fnCompareFieldRev($fieldName);
 }