Last active
April 29, 2020 16:48
-
-
Save DLzer/fb8b5303619de4802d4d436d4faf58e9 to your computer and use it in GitHub Desktop.
PHP ArrayIteration Previous
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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