PHP Code:
temp.myArray = {"test1", "test2", "test3"};
if ("test1" in myArray) {
// it is in the array
}
if (! ("test4" in myArray)) {
// not in the array, add it
myArray.add("test4");
}
Keep in mind that for checking if an object is in an array you
must enclose the "in" statement in parenthesis. Otherwise the "not" symbol (exclamation point) is taken to indicate that the variable should be "not" what it is.
Correct:
PHP Code:
if (! (obj in array)) {
Incorrect:
PHP Code:
if (! obj in array) {