一个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() 例子
实例代码如下:
- <?php
- $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() 严格类型检查例子
实例代码如下:
- <?php
- $a = array('1.10', 12.4, 1.13);
- if (in_array('12.4', $a, true)) {
- echo "'12.4' found with strict checkn";
- }
- if (in_array(1.13, $a, true)) {
- echo "1.13 found with strict checkn";
- }
- ?>
注:in_array函数返回的是0,1
当转换为 boolean 时,以下值被认为是 FALSE:
布尔值 FALSE
整型值 0(零)
浮点型值 0.0(零)
空白字符串和字符串 "0"
没有成员变量的数组
没有单元的对象
特殊类型NULL(包括尚未设定的变量)
所有其它值都被认为是 TRUE(包括任何资源).
警告
-1 和其它非零值(不论正负)一样,被认为是 TRUE
波比源码 » in_array()定义和用法
levofloxacin 250mg usa brand levaquin 250mg
spironolactone 100mg tablet order spironolactone 100mg without prescription order diflucan 100mg for sale
sildenafil uk purchase careprost robaxin pills
buy indocin 75mg sale purchase suprax pill oral amoxicillin 250mg
buy cialis tablets tadalafil lowest price female viagra
buy doxycycline online clomiphene pill buy furosemide without prescription
buy benicar 10mg pills olmesartan 10mg usa acetazolamide 250mg canada
order prograf pill brand labetalol 100mg purchase ursodiol pills
us pharmacy cialis Cialis samples sildenafil 100mg drug
cialis generic buy anafranil generic buy clomipramine 50mg
cheap amlodipine 10mg viagra pills cheap tadalafil online
zyvox cost real casino golden nugget online casino
cialis daily buy generic cialis 10mg order sildenafil 50mg
order triamcinolone 10mg pills buy triamcinolone 4mg online cheap clarinex 5mg price
generic sumatriptan 25mg purchase avodart pill avodart generic
real money slots free spins no deposit online roulette game online roulette game real money
buy generic tamsulosin 0.2mg buy tamsulosin sale spironolactone 25mg brand
zocor 10mg us purchase proscar pills proscar 1mg cost
sildenafil 50mg viagra for men cialis online
pala casino online order tadalafil 40mg without prescription tadalafil 40mg generic
paper help online thesis writing price of stromectol