Why doesn't my foreach loop work?
Posted: Tue Apr 20, 2004 12:40 am
Hi,
Been looking at this for ages but I can't figure out why it doesn't work:
I just get the else statement each time except for when I change:
to
Then that one works. It's as if it'll only read the first element in my array???
Where am I going wrong?
Been looking at this for ages but I can't figure out why it doesn't work:
Code: Select all
$collective = array ('man', 'cat', 'water');
foreach ($collective as $n) {
if ($n == 'cat') {
$_SESSION['val1'] = 'cat';
echo 'Success! '.$n.' found';
echo '<a href="doit.php? '. SID .' ">Do This</a>';
exit();
} else {
echo 'not found';
exit();
}Code: Select all
if ($n == 'cat') {Code: Select all
if ($n == 'man') {Where am I going wrong?