Welcome to WebmasterWorld Guest from 54.196.238.210

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

remove a select option from loop if equals

     

ahmed24

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

5+ Year Member



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]

ahmed24

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

5+ Year Member



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

BungeeJumper

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

5+ Year Member



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>";
}
}

ahmed24

1:03 pm on Sep 15, 2009 (gmt 0)

5+ Year Member



that works much better thanks
 

Featured Threads

Hot Threads This Week

Hot Threads This Month