var cat = [];
cat.push('1');
cat.push('2');
cat.push('3');
cat.push('1');
cat.push('2');
cat.push('3');
var found = $.inArray('1', cat) > -1;
var found = $.inArray('1', cat) > -1;
array_seach()
, try the following:if(($key = array_search($del_val, $messages)) !== false) {
unset($messages[$key]);
}
array_search()
returns the key of the element it finds, which can be used to remove that element from the original array using unset()
. It will return FALSE
on failure, however it can return a "falsey" value on success (your key may be 0
for example), which is why the strict comparison !==
operator is used.if()
statement will check whether array_search()
returned a value, and will only perform an action if it did.