Skip to content

Instantly share code, notes, and snippets.

View davisngl's full-sized avatar

Dāvis Naglis davisngl

  • Riga, Latvia
View GitHub Profile
@davisngl
davisngl / NextItemAwareIterator.php
Last active January 18, 2024 13:30
Next item aware iterator
<?php
$collection = collect(['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten']);
$iterator = $collection->getIterator();
foreach ($iterator as $item) {
$iterator->next();
// Next item in collection. Before doing anything with it
// should check if the "next" one is not null.