...

View Full Version : While Loop hiccup?



mOrloff
03-14-2009, 11:05 PM
I'm sure it's simple, but what am I missing?
When I run this:


$test=array('to','the','moon','alice');

if(is_array($test)){
$rowCount=count($test);
$i=0;
while($i<=$rowCount){
$var=$test[$i];
switch($var){
case "to":
$blah="To";
break;
case "the":
$blah=" the";
break;
case " moon":
$blah="moon";
break;
case "alice":
$blah=" Alice!";
break;
}
print $blah;
$i++;
}


I am getting "To the moon Alice! Alice!".
Why am I getting a repeat on my last value?

~ Mo

Iszak
03-14-2009, 11:16 PM
while ($i <= $rowCount)

to


while ($i < $rowCount)

mOrloff
03-14-2009, 11:28 PM
Aaahh!
Thanks!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum