Solved

# if \$variable !=('term1','term2','term3')

Posted on 2011-03-17
Medium Priority
346 Views
if \$variable !=('term1','term2','term3')

is this the correct syntax
0
Question by:rgb192
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 3
• 3
• 2
• +1

LVL 8

Expert Comment

ID: 35159226
``````if (\$variable != 'term1' OR \$variable != 'term2' OR \$variable != 'term3') {
//
}
``````
0

LVL 12

Expert Comment

ID: 35159241
if (\$variable != 'term1' || \$variable != 'term2' || \$variable != 'term3') {
//
}

|| is or
&& is and
0

Author Comment

ID: 35159258
i have 100 terms
can I do a list or array
0

LVL 8

Expert Comment

ID: 35159284
``````\$array = array(
'term1',
'term2',
);

if (! in_array(\$variable, \$array)) {
//
}
``````
0

LVL 12

Expert Comment

ID: 35159285
\$a = array('1.10', 12.4, 1.13);

if (in_array('12.4', \$a, true)) {
echo "'12.4' found with strict check\n";
}

http://php.net/manual/en/function.in-array.php
0

LVL 12

Expert Comment

ID: 35162723
will go with enachemc, +1 for this...
0

Author Comment

ID: 35167686
is there a way to do a for loop

because I would have to repeat myself in the if...
0

LVL 8

Accepted Solution

Rik-Legger earned 2000 total points
ID: 35167783
You mean like this?

``````<?php

\$array = array(
'term1',
'term2',
);

foreach (\$array as \$value) {
if (\$value != \$variable) {
//
}
}

?>
``````
0

Author Closing Comment

ID: 35245430
thanks
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.