in_array()定义和用法
一个php入门的基础教程关于in_array函数的使用方法,有需要的朋友可以参考一下。
bool in_array ( mixed $needle , array $haystack [, bool $strict ] )
在 haystack 中搜索 needle,如果找到则返回 TRUE,否则返回 FALSE。
如果第三个参数 strict 的值为 TRUE 则 in_array() 函数还会检查 needle 的类型是否和 haystack 中的相同。
Note:
如果 needle 是字符串,则比较是区分大小写的。
Note:
在 PHP 版本 4.2.0 之前,needle 不允许是一个数组。
注释:如果 value 参数是字符串,且 type 参数设置为 true,则搜索区分大小写。
Example #1 in_array() 例子
代码如下 | 复制代码 |
$os = array("Mac", "NT", "Irix", "Linux"); if (in_array("Irix", $os)) { echo "Got Irix"; } if (in_array("mac", $os)) { echo "Got mac"; } ?> |
第二个条件失败,因为 in_array() 是区分大小写的,所以以上程序显示为:
Got Irix
Example #2 in_array() 严格类型检查例子
代码如下 | 复制代码 |
$a = array('1.10', 12.4, 1.13); if (in_array('12.4', $a, true)) { |
注:in_array函数返回的是0,1
当转换为 boolean 时,以下值被认为是 FALSE:
布尔值 FALSE
整型值 0(零)
浮点型值 0.0(零)
空白字符串和字符串 "0"
没有成员变量的数组
没有单元的对象
特殊类型NULL(包括尚未设定的变量)
所有其它值都被认为是 TRUE(包括任何资源)。
警告
-1 和其它非零值(不论正负)一样,被认为是 TRUE

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor