Welcome to WebmasterWorld Guest from 54.196.233.208

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

remove a select option from loop if equals

     
12:21 pm on Sep 15, 2009 (gmt 0)

Junior Member

5+ Year Member

joined:July 17, 2006
posts:137
votes: 0


hi,

i have a loop which displays select options like this:

foreach($codes as $key => $val){
echo "<option value='CODE_".$codes[$key]['ID']."'>".$codes[$key]['TITLE']."</option>";
}

I also have a variable called $remove

I would like to know how i can skip a loop in my code if the $codes[$key]['TITLE'] value matches the $remove variable value ?

any ideas?

thanks

[edited by: ahmed24 at 12:50 pm (utc) on Sep. 15, 2009]

12:50 pm on Sept 15, 2009 (gmt 0)

Junior Member

5+ Year Member

joined:July 17, 2006
posts:137
votes: 0


i think i have figured it out, the following way seems to work:

if ($codes[$key]['TITLE'] == $remove) continue;

can anyone confirm if this is the correct way?

thanks

12:54 pm on Sept 15, 2009 (gmt 0)

New User

5+ Year Member

joined:Aug 6, 2009
posts: 17
votes: 0


echo everything that is not equal - the equal one(s) won't be echoed 'not equal
foreach($codes as $key => $val){
if (the $codes_RET[$key]['TITLE'] value != the $remove variable value)
{
echo "<option value='CODE_".$codes[$key]['ID']."'>".$codes_RET[$key]['TITLE']."</option>";
}
}
1:03 pm on Sept 15, 2009 (gmt 0)

Junior Member

5+ Year Member

joined:July 17, 2006
posts:137
votes: 0


that works much better thanks