Created
July 17, 2014 14:32
-
-
Save mudge/3c1ac272f9856c1d5bc2 to your computer and use it in GitHub Desktop.
Iterate over an array as a sliding window of element pairs.
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 | |
$a = array(1, 2, 3); | |
$pairs = array_map(null, $a, array_slice($a, 1)); | |
/** | |
* Prints: | |
* (1,2)(2, 3)(3, ) | |
*/ | |
foreach ($pairs as list($x, $y)) { | |
echo "({$x}, {$y})"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
+1