Page 1 of 1

Not equal array variables

Posted: Fri Jan 09, 2004 8:32 am
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

Posted: Fri Jan 09, 2004 8:38 am
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

Posted: Fri Jan 09, 2004 8:42 am
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

Posted: Fri Jan 09, 2004 8:44 am
by tsg
Thanks guys, I really appreciate it!!

Tim