Skip to content

Instantly share code, notes, and snippets.

@thrashr888
Created November 21, 2010 22:08
Show Gist options
  • Select an option

  • Save thrashr888/709203 to your computer and use it in GitHub Desktop.

Select an option

Save thrashr888/709203 to your computer and use it in GitHub Desktop.
you can reset an array within a while() but not a foreach();
<?php
$test = array(1,2,3,4,5,6,7,8,9,0);
$find = 4;
foreach($test as $t){
echo $t.',';
if($t=='4' && $find==4){
echo 'found!,';
$find = 6;
reset($test);
}
}
echo ';<br><br><br>'."\n\n";
reset($test);
$find = 4;
while(list($i,$t) = each($test)){
echo $t.',';
if($t=='4' && $find==4){
echo 'found!,';
$find = 6;
reset($test);
}
}
echo ';';exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment