Skip to content

Instantly share code, notes, and snippets.

@jessegreathouse
Created November 19, 2010 21:19
Show Gist options
  • Save jessegreathouse/707195 to your computer and use it in GitHub Desktop.
Save jessegreathouse/707195 to your computer and use it in GitHub Desktop.
php you vex me.
<?php
//a list of unknown size
$bars=array();
// I want to walk through the array and take the first one that isn't empty
//this code looks wierd but it's a compromise.
foreach ($bars as $bar) { if ($foo = $bar) { break 1; }
//this is what i wanted to do
while (!$foo = current($bars)) {
next($bars);
}
//Im trying to say if $referrer isn't null to keep the loop open until current returns a non empty
//The problem is that this type of while loop seems to only work if im testing for a positive instead
//of a negative because the negative just keeps the loop open forever.
//is my compromise the only adequate solution?
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment