码迷,mamicode.com
首页 > Web开发 > 详细

PHP语法-该注意的细节

时间:2018-05-20 14:23:24      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:类型   nbsp   字符串   php   color   细节   分享   str   严格   

php in_array(mixed $needle, array $haystack[, bool $strict = FALSE] )

注意: 一、如果$needle 是字符串,则比较是区分大小写的。

      二、如果$strict = TRUE 则in_array 会比较$needle 和$haystack 的类型是否一致,不一致,则返回FALSE

技术分享图片
 1 //例一、in_array 严格类型检查例子
 2 <?php
 3     $a = array(‘1.12‘, 2.16, 3.18);
 4     if(in_array(‘2.16‘, $a, true))
 5     {
 6         echo "‘2.16‘ found with strict check\n";         
 7     }
 8     if(in_array(3.18, $a, true))
 9     {
10         echo "3.18 found with strict check\n";         
11     }
12 ?>
13 //output 3.18 found with struct check
14 //例二、in_array()中用数组作为$needle
15  <?php
16     $a = array(array(‘p‘, ‘h‘), array(‘j‘, ‘q‘), ‘o‘);
17     if(in_array(array(‘p‘, ‘h‘), $a))
18     {
19         echo "‘ph‘ was found\n";
20     }
21     if(in_array(array(‘f‘, ‘i‘), $a))
22     {
23         echo "‘fi‘ was found\n";
24     }
25     if(in_array(‘o‘, $a))
26     {
27         echo "‘fi‘ was found\n";
28     }
29  ?>
30 //output ‘ph‘ was found
31              ‘o‘ was found
32 
33     
View Code

 

PHP语法-该注意的细节

标签:类型   nbsp   字符串   php   color   细节   分享   str   严格   

原文地址:https://www.cnblogs.com/jasonxu19900827/p/9063202.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!