On this page
Class ZipIterator
Creates an iterator that returns elements grouped in pairs
Example
$iterator = new ZipIterator([[1, 2], [3, 4]]);
 $iterator->toList(); // Returns [[1, 3], [2, 4]]You can also chose a custom function to zip the elements together, such as doing a sum by index:
Example
$iterator = new ZipIterator([[1, 2], [3, 4]], function ($a, $b) {
   return $a + $b;
 });
 $iterator->toList(); // Returns [4, 6]- MultipleIterator implements Iterator, Traversable
- Cake\Collection\Iterator\ZipIterator implements Cake\Collection\CollectionInterface, Serializable uses Cake\Collection\CollectionTrait 
Inherited Constants
- MIT_KEYS_ASSOC,- MIT_KEYS_NUMERIC,- MIT_NEED_ALL,- MIT_NEED_ANY
Properties summary
- 
    $_callbackprotectedThe function to use for zipping items togethercallable
- 
    $_iteratorsprotectedContains the original iterator objects that were attachedarray
Method Summary
- 
    __construct() publicCreates the iterator to merge together the values by for all the passed iterators by their corresponding index. 
- 
    current() publicReturns the value resulting out of zipping all the elements for all the iterators with the same positional index. 
- 
    serialize() publicReturns a string representation of this object that can be used to reconstruct it 
- 
    unserialize() publicUnserializes the passed string and rebuilds the ZipIterator instance
Method Detail
__construct()source public
__construct( array $sets , callable|null $callable = null )Creates the iterator to merge together the values by for all the passed iterators by their corresponding index.
Parameters
- 
     array $sets
- The list of array or iterators to be zipped.
- 
     callable|null $callableoptional null
- The function to use for zipping the elements of each iterator.
Overrides
MultipleIterator::__construct()
  current()source public
current( )Returns the value resulting out of zipping all the elements for all the iterators with the same positional index.
Returns
mixedOverrides
MultipleIterator::current()
   Implementation of
Iterator::current()
  serialize()source public
serialize( )Returns a string representation of this object that can be used to reconstruct it
Returns
stringImplementation of
Serializable::serialize()
  unserialize()source public
unserialize( string $iterators )Unserializes the passed string and rebuilds the ZipIterator instance
Parameters
- 
     string $iterators
- The serialized iterators
Implementation of
Serializable::unserialize()
  Methods used from Cake\Collection\CollectionTrait
_unwrap()source public
_unwrap( )append()source public
append( $items )appendItem()source public
appendItem( $item , $key = null )avg()source public
avg( $matcher = null )cartesianProduct()source public
cartesianProduct( callable $operation = null , callable $filter = null )Parameters
- 
     callable $operationoptional null
- Operation
- 
     callable $filteroptional null
- Filter
Returns
Cake\Collection\CollectionInterfaceThrows
LogicExceptionchunk()source public
chunk( $chunkSize )chunkWithKeys()source public
chunkWithKeys( $chunkSize , $preserveKeys = true )combine()source public
combine( $keyPath , $valuePath , $groupPath = null )compile()source public
compile( $preserveKeys = true )contains()source public
contains( $value )countBy()source public
countBy( $callback )each()source public
each( callable $c )every()source public
every( callable $c )extract()source public
extract( $matcher )first()source public
first( )firstMatch()source public
firstMatch( array $conditions )groupBy()source public
groupBy( $callback )indexBy()source public
indexBy( $callback )isEmpty()source public
isEmpty( )jsonSerialize()source public
jsonSerialize( )last()source public
last( )lazy()source public
lazy( )listNested()source public
listNested( $dir = 'desc' , $nestingKey = 'children' )Returns
Cake\Collection\Iterator\TreeIteratormatch()source public
match( array $conditions )max()source public
max( $callback , $type = \SORT_NUMERIC )median()source public
median( $matcher = null )min()source public
min( $callback , $type = \SORT_NUMERIC )nest()source public
nest( $idPath , $parentPath , $nestingKey = 'children' )newCollection()source protected
newCollection( ... $args )Returns a new collection.
Allows classes which use this trait to determine their own type of returned collection interface
Parameters
- 
     ... $args
- $args Constructor arguments.
Returns
Cake\Collection\CollectionInterfaceoptimizeUnwrap()source protected
optimizeUnwrap( )Unwraps this iterator and returns the simplest traversable that can be used for getting the data out
Returns
Traversable|arrayprepend()source public
prepend( $items )prependItem()source public
prependItem( $item , $key = null )reduce()source public
reduce( callable $c , $zero = null )sample()source public
sample( $size = 10 )shuffle()source public
shuffle( )skip()source public
skip( $howMany )some()source public
some( callable $c )sortBy()source public
sortBy( $callback , $dir = \SORT_DESC , $type = \SORT_NUMERIC )sumOf()source public
sumOf( $matcher = null )take()source public
take( $size = 1 , $from = 0 )takeLast()source public
takeLast( $howMany )through()source public
through( callable $handler )toArray()source public
toArray( $preserveKeys = true )toList()source public
toList( )transpose()source public
transpose( )Returns
Cake\Collection\CollectionInterfaceThrows
LogicExceptionunfold()source public
unfold( callable $transformer = null )unwrap()source public
unwrap( )zip()source public
zip( $items )zipWith()source public
zipWith( $items , $callable )Magic methods inherited from Cake\Collection\CollectionInterface
Properties detail
© 2005–present 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.
 https://api.cakephp.org/3.8/class-Cake.Collection.Iterator.ZipIterator.html