Skip to content

Instantly share code, notes, and snippets.

@caefer
Created July 28, 2011 15:38
Show Gist options
  • Select an option

  • Save caefer/1111774 to your computer and use it in GitHub Desktop.

Select an option

Save caefer/1111774 to your computer and use it in GitHub Desktop.
<?php
$data = array(/*..some huge array..*/);
do {
$current = current($data);
$key = key($data);
$next = next($data);
/*..some action..*/
if (/*..some condition.. */) {
// add something to the array after the current position
array_splice($data, $key, 0, /*..some payload.. */);
// skip the payload we just added
$next = next($data);
/**
* unfortunately array_splice() reset the array..
* so the pointer is now pointing to the second element..
*/
}
} while ($next);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment