在php数组函数中,array_search()函数在一个数组中搜索一个指定的值,如果找到则返回相应的键,否则返回false。
形式如下:
mixed array_search(mixed needle,array haystack[,boolean strict])
例子,在$fruits中搜索一个特定的日期(December 7),如果找到,则返回相应州的有关信息:
<?php $fruits["apple"] = "red"; $fruits["banana"] = "yellow"; $fruits["watermelon"]="green"; $founded = array_search("green", $fruits); if($founded) printf("%s was founded on %s.",$founded, $fruits[$founded]); //watermelon was founded on green. ?>