PHP in_array

1.函数的作用:判读一个元素是否在一个数组存在

2.函数的参数:

  @param mixed $needle

  @param array $array

3. if it’s ok to use isset() function ,then better to use the isset() function instead of in_array() function.

4.

例子一:

 1 <?php
 2 $arr = [
 3     '1314LoveZhangbiyu',
 4 ];
 5 if(in_array(1314,$arr)){
 6     echo '1314';
 7     echo "\n";
 8 }
 9 
10 if(in_array('1314',$arr)){
11     echo 'string 1314 is in!';
12     echo "\n";
13 }else{
14     echo 'string 1314 is not in!';
15     echo "\n";
16 }

 例子二:

1 <?php
2 $a = array('0' => 'Opt 1', '1' => 'Opt 2', '2' => 'Opt 3');
3 $v = 'sql injection';
4 var_dump(in_array($v, array_keys($a)));

 

posted @ 2017-06-15 08:45  GoodByeZ  阅读(154)  评论(0编辑  收藏  举报