An iterator that will return the passed items in order. The order is given by the value returned in a callback function that maps each of the elements.
$items = [$user1, $user2, $user3];
$sorted = new SortIterator($items, function ($user) {
return $user->age;
});
// output all user name order by their age in descending order
foreach ($sorted as $user) {
echo $user->name;
} This iterator does not preserve the keys passed in the original elements.
Cake\Collection\Collection implements Cake\Collection\CollectionInterface, Serializable uses Cake\Collection\CollectionTrait
Cake\Collection\Iterator\SortIterator Wraps this iterator around the passed items so when iterated they are returned in order.
__construct( array|Traversable $items , callable|string $callback , integer $dir SORT_DESC , integer $type SORT_NUMERIC )
Wraps this iterator around the passed items so when iterated they are returned in order.
The callback will receive as first argument each of the elements in $items, the value returned in the callback will be used as the value for sorting such element. Please note that the callback function could be called more than once per element.
$items $callback A function used to return the actual value to be compared. It can also be a string representing the path to use to fetch a column or property in each element
$dir optional SORT_DESC $type optional SORT_NUMERIC the type of comparison to perform, either SORT_STRING SORT_NUMERIC or SORT_NATURAL
Cake\Collection\Collection::__construct() __debugInfo( )
Returns an array that can be used to describe the internal state of this object.
count( )
Throws an exception.
Issuing a count on a Collection can have many side effects, some making the Collection unusable after the count operation.
serialize( )
Returns a string representation of this object that can be used to reconstruct it
Serializable::serialize() unserialize( string $collection )
Unserializes the passed string and rebuilds the Collection instance
$collection Serializable::unserialize() _unwrap( )
Backwards compatible wrapper for unwrap()
append( $items )
chunk( $chunkSize )
combine( $keyPath , $valuePath , $groupPath null )
compile( $preserveKeys true )
contains( $value )
countBy( $callback )
each( callable $c )
every( callable $c )
extract( $matcher )
first( )
firstMatch( array $conditions )
groupBy( $callback )
indexBy( $callback )
isEmpty( )
jsonSerialize( )
last( )
listNested( $dir 'desc' , $nestingKey 'children' )
Cake\Collection\Iterator\TreeIteratormatch( array $conditions )
max( $callback , $type SORT_NUMERIC )
min( $callback , $type SORT_NUMERIC )
nest( $idPath , $parentPath )
reduce( callable $c , $zero null )
sample( $size 10 )
shuffle( )
skip( $howMany )
some( callable $c )
sortBy( $callback , $dir SORT_DESC , $type SORT_NUMERIC )
sumOf( $matcher null )
take( $size 1 , $from 0 )
through( callable $handler )
toArray( $preserveKeys true )
toList( )
unfold( callable $transformer null )
unwrap( )
zip( $items )
zipWith( $items , $callable )
© 2005–2016 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
http://api.cakephp.org/3.2/class-Cake.Collection.Iterator.SortIterator.html