Skip to content

Instantly share code, notes, and snippets.

@DLzer
Last active April 29, 2020 16:48
Show Gist options
  • Save DLzer/fb8b5303619de4802d4d436d4faf58e9 to your computer and use it in GitHub Desktop.
Save DLzer/fb8b5303619de4802d4d436d4faf58e9 to your computer and use it in GitHub Desktop.
PHP ArrayIteration Previous
<?php
$array = array('1' => 'one',
'2' => 'two',
'3' => 'three');
$arrayobject = new ArrayObject($array);
for($iterator = $arrayobject->getIterator();
$iterator->valid();
$iterator->next()) {
echo $iterator->key();
if($iterator->key() - 1 > 0) {
echo $iterator->offsetGet($iterator->key() - 1);
}
}
// Outputs 1one2two3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment