Solved

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

Posted on 2011-03-17
9
302 Views
Last Modified: 2012-05-11
if $variable !=('term1','term2','term3')

is this the correct syntax
0
Comment
Question by:rgb192
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 8

Expert Comment

by:Rik-Legger
ID: 35159226
if ($variable != 'term1' OR $variable != 'term2' OR $variable != 'term3') {
    // 
}

Open in new window

0
 
LVL 12

Expert Comment

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

|| is or
&& is and
0
 

Author Comment

by:rgb192
ID: 35159258
i have 100 terms
can I do a list or array
0
 
LVL 8

Expert Comment

by:Rik-Legger
ID: 35159284
$array = array(
    'term1',
    'term2',
);

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

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 12

Expert Comment

by:enachemc
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

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

Author Comment

by:rgb192
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

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

<?php 

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

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

?>

Open in new window

0
 

Author Closing Comment

by:rgb192
ID: 35245430
thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now