Home > php教程 > php手册 > body text

php-Arrays函数-array_search-在数组中查找给定的值并返回相应的键名

WBOY
Release: 2016-06-13 10:49:54
Original
720 people have browsed it

array_search() 在数组中查找给定的值并返回相应的键名

【功能】
         该函数将在指定的数组中查找某一个给定的值,并在找到的情况下返回该值的键名否则返回false。
【使用范围】
         php4>=4.0.5、php5.
【使用】
         mixed array_search( mixed needle,array haystack[,bool strict]  )
         needle/必需/要查找的值
         haystack/必需/即将进行搜索操作的原始数组
         strict/可选/true 则函数还将在haystack中检查needle的类型
         如果needle在haystack中不止一次出现,则返回第一个匹配的建
【示例】
[php]
$array=array('blue','red','green','red'); 
echo $key=array_search('green',$array); 
echo "\n"; 
echo $key=array_search('red',$array,false); 
/*
2
1
*/ 

 


摘自 zuodefeng的笔记

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!