Skip to content

Instantly share code, notes, and snippets.

@claussni
Created July 29, 2011 08:53
Show Gist options
  • Save claussni/1113464 to your computer and use it in GitHub Desktop.
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
<?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