in_array checks if a value exists in an array 注意是值
bool in_array ( mixed $needle
, array $haystack
[, bool $strict
= FALSE
] )
array_key_exists — Checks if the given key or index exists in the array 注意是键
array_keys — Return all the keys or a subset of the keys of an array 返回特定值的key的数组
array array_keys ( array $input
[, mixed $search_value
= NULL
[, bool $strict
= false ]] )
Returns an array of all the keys in input
.
http://www.php.net/manual/en/function.array-keys.php
array_search — Searches the array for a given value and returns the corresponding key if successful
mixed array_search ( mixed $needle
, array $haystack
[, bool $strict
= false ] )
<?php $array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red'); $key = array_search('green', $array); // $key = 2; $key = array_search('red', $array); // $key = 1; ?>