Log in

View Full Version : php equivalent for SQL IN(...) clause



kuau
04-07-2009, 10:29 PM
I would like to be able to say in php something like this:


if(field1 != 0 AND field2 NOT IN (5,8,10) {
do something;
}

Is there anything like this in php? or do I have to say:


if(field1 != 0 AND (field2 != 5 AND field2 != 8 AND field2 != 10)){
do something;
}

The second way seems so messy. Thanks!

techietim
04-08-2009, 12:34 AM
$arr = array(5,8,10);
if($field1 != 0 AND !in_array($field2, $arr)) {
do something;
}

kuau
04-08-2009, 12:52 AM
Exactly what I needed... thanks, techietim! :)