当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > in_array() 函数

PHP
PHP Libxml
PHP Math
PHP Misc
PHP MySQL
PHP SimpleXML
PHP String
PHP XML
PHP Zip
PHP Mail
用PHP5的DirectoryIterators递归扫描目录
PHP 阻止SQL注入式攻击
PHP5面向对象 - 基础 - 类和对象
PHP5面向对象 - 基础 - 类的属性( public )
PHP5面向对象 - 基础 - 类的属性( private )
PHP5面向对象 - 基础 - 方法
PHP5面向对象 - 基础 - 对象的比较
php5面向对象 - 基础 - 构造函数
php5面向对象 - 基础 - 析构函数
用PHP控制用户的浏览器 - ob*函数的使用
PHP PDO 学习笔记

PHP 中的 in_array() 函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 479 ::
收藏到网摘: n/a

Definition and Usage
定义和用法

The in_array() function searches an array for a specific value.
in_array()函数的作用是:在数组中搜索指定的值。

This function returns TRUE if the value is found in the array, or FALSE otherwise.
如果这个值存在于数组中,该函数将返回True,否则将返回False。

Syntax
语法

in_array(search,array,type)

Parameter参数 Description描述
search Required. Specifies the what to search for
必要参数。指定需要搜索的值
array Required. Specifies the array to search
必要参数。指定在哪个数组中进行搜索
type Optional. If this parameter is set, the in_array() function searches for the search-string and specific type in the array
可选参数。如果设置这个参数,那么in_array()函数将搜索数组中指定要搜索的字符串和详细的类型


Tips and Notes
注意点

Note: If the search parameter is a string and the type parameter is set to TRUE, the search is case-sensitive.
注意:如果搜索(search)参数是一个字符串,并且type参数设置为TRUE,那么整个搜索将是区分大小写的。


Example 1
案例1

<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");
if (in_array("Glenn",$people)) { echo "Match found"; }
else { echo "Match not found"; }
?>

The output of the code above will be:
上述代码将输出下面的结果:

Match found


Example 2
案例2

<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland", 23);
if (in_array("23",$people, TRUE)) { echo "Match found<br />"; }
else { echo "Match not found<br />"; }
if (in_array("Glenn",$people, TRUE)) { echo "Match found<br />"; }
else { echo "Match not found<br />"; }
if (in_array(23,$people, TRUE)) { echo "Match found<br />"; }
else { echo "Match not found<br />"; }
?>

The output of the code above will be:
上述代码将输出下面的结果:

Match not found
Match found
Match not found

评论 (0) All

登陆 | 还没注册?