Solved

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

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

is this the correct syntax
0
Comment
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
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

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

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

Open in new window

0
 
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

749 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