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

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

is this the correct syntax
LVL 1
rgb192Asked:
Who is Participating?
 
Rik-LeggerConnect With a Mentor Commented:
You mean like this?

<?php 

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

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

?>

Open in new window

0
 
Rik-LeggerCommented:
if ($variable != 'term1' OR $variable != 'term2' OR $variable != 'term3') {
    // 
}

Open in new window

0
 
enachemcCommented:
if ($variable != 'term1' || $variable != 'term2' || $variable != 'term3') {
    //
}

|| is or
&& is and
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
rgb192Author Commented:
i have 100 terms
can I do a list or array
0
 
Rik-LeggerCommented:
$array = array(
    'term1',
    'term2',
);

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

Open in new window

0
 
enachemcCommented:
$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
 
Avinash ZalaWeb ExpertCommented:
will go with enachemc, +1 for this...
0
 
rgb192Author Commented:
is there a way to do a for loop

because I would have to repeat myself in the if...
0
 
rgb192Author Commented:
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.