Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why doesn't this Inner loop execute? 1

Status
Not open for further replies.

sen5241b

IS-IT--Management
Sep 27, 2007
199
US
I'm looked at this for way too long and I can't see why the inner FOR loop won't execute. I hope its not something incredibly obvious that I've missed. (I swear, I've had no beer yet.)

Code:
<?PHP
//  find any word that is in both arrays
//
$CheckstrArray = array("dog", "cat", "elephant", "horse", "man", "snake", "insect");
$WordsArray = array("lion", "horse", "mule", "bird", "cat", "fish", "insect");
$z = 0;
$WordsArrayCount = count($WordsArray);
echo ' <br> $WordsArrayCount=' . $WordsArrayCount;
foreach ($CheckstrArray as $key=>$value)
	{
		echo  '<br> OUTER LOOP strtolower($value)=' . strtolower($value);
		for ($y=0; $y<WordsArrayCount; $y++)	
		{
			echo  '<br> in INNER LOOP!!! ';
			if ($WordsArray[$y] == strtolower($value))
				{ echo '<br> they match!'; }
			echo  '<br> $WordsArray[$y]=' . $WordsArray[$y];
		}
	}
echo '<br> fin';
?>

The output I get is:

$WordsArrayCount=7
OUTER LOOP strtolower($value)=dog
OUTER LOOP strtolower($value)=cat
OUTER LOOP strtolower($value)=elephant
OUTER LOOP strtolower($value)=horse
OUTER LOOP strtolower($value)=man
OUTER LOOP strtolower($value)=snake
OUTER LOOP strtolower($value)=insect
fin
 
Code:
for ($y=0; $y<WordsArrayCount; $y++)

should be ?:

Code:
for ($y=0; $y<[red]$[/red]WordsArrayCount; $y++)

Chris
 
Alright alright, so I drank a little beer.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top