Giv开发者_JS百科en a value, #some_id = x, what's the proper syntax or method to test that the id does not exist in a collection of id's?
For example...
if($some_id not in array(3, 5, 9)){
  //do something
}
$theArray = array(3, 5, 9);
if(! in_array($x, $theArray)){
    // do something
}
http://php.net/manual/en/function.in-array.php
in_array too slow
$array = array_flip($array);
if(!isset($array[$some_id])){ // do something }
The in_array answers are correct, but in case there's some ambiguity between the term "id" and "key", if what you're trying to do is check if a key exists, you could do either of the following:
if (array_key_exists($key, $array)) ...
or...
if (isset($array[$key])) ...
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论