Not equal array variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tsg
Forum Contributor
Posts: 142
Joined: Sun Jan 12, 2003 9:22 pm
Location: SE, Alabama
Contact:

Not equal array variables

Post by tsg »

hello,

I am at a loss on something. What I am trying to do is change my following code so I can use an array.

Code: Select all

<? 
if(($this !== "thing1" AND $this !== "thing2" AND $this !== "thing3")) {
print "Then do this if not equal to any of those";
}
?>
What I want to do is put "thing1" "thing2" "Thing3" into an array and check from there if possible (so I can call the variables on different pages and not have to recode each page for changes).

Any ideas?
Thanks,
Tim
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

variables in array

Code: Select all

<?php

$arra[]='thing1';
$arra[]='thing2';

if (in_array($this, $arra)){
  // do something
}

?>
check here:

http://www.php.net/manual/en/function.in-array.php
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

This might do it

Code: Select all

<?php
$array = array("thing1", "thing2", "thing3");

if (!in_array($this, $array)) {
    print "Then do this if not equal to any of those"; 
}

?>
avatar just beat me to it, but his code will run if the value exists in the array, whilst i think you wanted to execute the code if the none of the values existed in the array.

Mark
Last edited by JayBird on Fri Jan 09, 2004 8:44 am, edited 1 time in total.
tsg
Forum Contributor
Posts: 142
Joined: Sun Jan 12, 2003 9:22 pm
Location: SE, Alabama
Contact:

Post by tsg »

Thanks guys, I really appreciate it!!

Tim
Post Reply