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.
__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
$dir
optional SORT_DESC $type
optional SORT_NUMERIC InvalidArgumentException
Cake\Collection\Collection::__construct()
__debugInfo( )
Returns an array that can be used to describe the internal state of this object.
array
count( )
Throws an exception.
Issuing a count on a Collection can have many side effects, some making the Collection unusable after the count operation.
LogicException
serialize( )
Returns a string representation of this object that can be used to reconstruct it
string
Serializable::serialize()
unserialize( string $collection )
Unserializes the passed string and rebuilds the Collection instance
$collection
Serializable::unserialize()
_unwrap( )
Backwards compatible wrapper for unwrap()
Iterator
append( mixed $items )
Cake\Collection\CollectionInterface::append()
buffered( )
Cake\Collection\Iterator\BufferedIterator
Cake\Collection\CollectionInterface::buffered()
chunk( mixed $chunkSize )
Cake\Collection\CollectionInterface::chunk()
combine( mixed $keyPath , mixed $valuePath , mixed $groupPath null )
Cake\Collection\CollectionInterface::combine()
compile( mixed $preserveKeys true )
Cake\Collection\CollectionInterface::compile()
contains( mixed $value )
Cake\Collection\CollectionInterface::contains()
countBy( mixed $callback )
Cake\Collection\CollectionInterface::countBy()
every( callable $c )
Cake\Collection\CollectionInterface::every()
extract( mixed $matcher )
Cake\Collection\CollectionInterface::extract()
filter( callable $c null )
Cake\Collection\Iterator\FilterIterator
Cake\Collection\CollectionInterface::filter()
firstMatch( array $conditions )
Cake\Collection\CollectionInterface::firstMatch()
groupBy( mixed $callback )
Cake\Collection\CollectionInterface::groupBy()
indexBy( mixed $callback )
Cake\Collection\CollectionInterface::indexBy()
insert( mixed $path , mixed $values )
Cake\Collection\Iterator\InsertIterator
Cake\Collection\CollectionInterface::insert()
jsonSerialize( )
Cake\Collection\CollectionInterface::jsonSerialize()
listNested( mixed $dir 'desc' , mixed $nestingKey 'children' )
Cake\Collection\Iterator\TreeIterator
Cake\Collection\CollectionInterface::listNested()
map( callable $c )
Cake\Collection\Iterator\ReplaceIterator
Cake\Collection\CollectionInterface::map()
match( array $conditions )
Cake\Collection\CollectionInterface::match()
max( mixed $callback , mixed $type SORT_NUMERIC )
Cake\Collection\CollectionInterface::max()
min( mixed $callback , mixed $type SORT_NUMERIC )
Cake\Collection\CollectionInterface::min()
nest( mixed $idPath , mixed $parentPath )
Cake\Collection\CollectionInterface::nest()
reduce( callable $c , mixed $zero null )
Cake\Collection\CollectionInterface::reduce()
reject( callable $c )
Cake\Collection\Iterator\FilterIterator
Cake\Collection\CollectionInterface::reject()
sample( mixed $size 10 )
Cake\Collection\CollectionInterface::sample()
skip( mixed $howMany )
Cake\Collection\CollectionInterface::skip()
sortBy( mixed $callback , mixed $dir SORT_DESC , mixed $type SORT_NUMERIC )
Cake\Collection\CollectionInterface::sortBy()
stopWhen( mixed $condition )
Cake\Collection\Iterator\StoppableIterator
Cake\Collection\CollectionInterface::stopWhen()
sumOf( mixed $matcher null )
Cake\Collection\CollectionInterface::sumOf()
take( mixed $size 1 , mixed $from 0 )
Cake\Collection\CollectionInterface::take()
through( callable $handler )
Cake\Collection\CollectionInterface::through()
toArray( mixed $preserveKeys true )
Cake\Collection\CollectionInterface::toArray()
unfold( callable $transformer null )
Cake\Collection\CollectionInterface::unfold()
zipWith( mixed $items , mixed $callable )
Cake\Collection\CollectionInterface::zipWith()
_createMatcherFilter( array $conditions )
Returns a callable that receives a value and will return whether or not it matches certain condition.
$conditions
callable
_extract( array|ArrayAccess $data , array $path )
Returns a column from $data that can be extracted by iterating over the column names contained in $path. It will return arrays for elements in represented with {*}
$data
$path
mixed
_propertyExtractor( string|callable $callback )
Returns a callable that can be used to extract a property or column from an array or object based on a dot separated path.
$callback
callable
_simpleExtract( array|ArrayAccess $data , array $path )
Returns a column from $data that can be extracted by iterating over the column names contained in $path
$data
$path
mixed
© 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.1/class-Cake.Collection.Iterator.SortIterator.html