Created
July 29, 2011 08:53
-
-
Save claussni/1113464 to your computer and use it in GitHub Desktop.
Given a PHP array "$array" and a seek position "$pos", this sets the internal array pointer to $pos in only 52 chars
This file contains 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 | |
// the array | |
$array = array('foot', 'bike', 'my'=>'car', 'plane', 'roller'); | |
// seek position | |
$pos="my"; | |
// seek array pointer, behaves end($array) if $pos is no array key | |
for($a=&$array,reset($a);key($a)!==$pos&&each($a);); | |
// should print "car" | |
echo ">".current($array)."<\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment