Home >Backend Development >PHP Tutorial >php在数组中查找指定值的方法_PHP

php在数组中查找指定值的方法_PHP

WBOY
WBOYOriginal
2016-06-01 11:06:141085browse

本文实例讲述了php在数组中查找指定值的方法。分享给大家供大家参考。具体如下:

php中有两个函数可以判断数组中是否包含指定的值,分别是:array_search($value, $array)和in_array($value, $array),array_search可以找出指定的值在数组中出现的位置,in_array函数只判断数组中是否存在指定的值,返回bool值

<&#63;php 
$array = array("Perl", "PHP", "Java", "PHP");
print("Search 1: ".array_search("PHP",$array)."\n");
print("Search 2: ".array_search("Perl",$array)."\n");
print("Search 3: ".array_search("C#",$array)."\n");
print("\n");
&#63;>

输出结果如下

Search 1: 1
Search 2: 0
Search 3:

希望本文所述对大家的php程序设计有所帮助。

Statement:
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