View Single Post
Old 11-08-2007, 06:02 AM   #6 (permalink)
Tanax
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Yea, andrew said the correct way to do that.

In your example it would be:
PHP Code:
// Loops through the array, where $c is the value of the current element
foreach($b as $c) {
// If the current element is equal to the value you want to match
if($c == $a) {
// Do what you want if the match was found
}
else {
// Optional, if the current element was NOT a match to the $a value
}

Also, remember, that if your array consist of 3 elements like this:
array('1', '2', '3');

And your $a = 1;

the "else" statement will execute all the times the if statement is NOT true.
So first time, the if statement will be true, but the 2 other loops, it won't.
Tanax is offline  
Reply With Quote