PHP code example of halfpastfouram / collection

1. Go to this page and download the library: Download halfpastfouram/collection library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

halfpastfouram / collection example snippets


$collection = new Collection\ArrayAccess( [ 0, 1, 2, 3 ] );
$collection[] = 0;
$collection[5] = 12;

foreach( $collection as $key => $value ) {
    var_dump( $key, $value );
}

$iterator   = $collection->getIterator();

// Jump forward to next position
$iterator->next();
var_dump( $iterator->current() );

// Go back one position
$iterator->previous();
var_dump( $iterator->getKey(), $iterator->current() );

// Receive the list of keys in the dataset.
var_dump( $iterator->calculateKeyMap() );