I am having a problem with an foreach, that his main propose is to check if a server is up, then access that file, and i'm stuck on an foreach that i want to make it repeat a step. For example i have the following code:
<?php
$Array = array("one","two","tree","four");
next($Array);
$i = 0;
foreach($Array as $Key=>$Value)
{
$i++;
echo "Key=".$Key." VAL=".$Value."<br>";
if($Key==2) prev($Array);
if($i==10) break;
}
?>
that is outputing:
Key=0 VAL=one
Key=1 VAL=two
Key=2 VAL=tree
Key=3 VAL=four
and i want to make it that it will output
Key=0 VAL=one
Key=1 VAL=two
Key=2 VAL=tree
Key=2 VAL=tree
Key=2 VAL=tree
Key=2 VAL=tree
Key=2 VAL=tree
Key=2 VAL=tree
Key=2 VAL=tree
Key=2 VAL=tree // till the $i is 10 therefore it's exits the foreach trough break;
and i have tried prev($Array); with no result.
I also been thinking about
while(true)
{
if(server exists)
{
echo "server is good";
break;
}
else
{
echo "server is BAD ... continueing";
prev($Array);
}
}
but this didn't worked for me either ... Can anyone help me with this??