Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 360
  • Last Modified:

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

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

is this the correct syntax
0
rgb192
Asked:
rgb192
  • 3
  • 3
  • 2
  • +1
1 Solution
 
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
 
rgb192Author Commented:
i have 100 terms
can I do a list or array
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
Rik-LeggerCommented:
You mean like this?

<?php 

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

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

?>

Open in new window

0
 
rgb192Author Commented:
thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now