View Single Post
  #2  
Old 05-23-2010, 07:27 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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) { 
__________________
Reply With Quote