Home > Backend Development > PHP Tutorial > array_keys()b函数?

array_keys()b函数?

WBOY
Release: 2016-06-23 14:23:39
Original
933 people have browsed it

http://docs.php.net/manual/zh/function.array-keys.php

<?   $x=array("1"=>"aa","2"=>"bb","3"=>"cc","4"=>"bb");   $y1=array_keys($x,bb,false);   $y2=array_keys($x,bb,true);   print_r($x);   print_r($y1);   print_r($y2);?>
Copy after login




函数第3个参数,有什么作用?
程序为什么出错了?




回复讨论(解决方案)

看看这个:http://baike.baidu.com/view/4068562.htm赫然看开朗

改成这样:$y2=array_keys($x,"bb",true); 就对了

程序为什么出错了?
因为 bb 不是常量,而你又没有用引号括起
第三个参数指定是否检查数据类型

 strict

    判断在搜索的时候是否该使用严格的比较(===)。

出错是因为 $y1=array_keys($x, bb,false); 这里的bb没加引号,php首先会认为它是一个常量,而你的代码中没有常量,所以就报错了。

第三个参数是根据类型返回带有指定值的键名,
$x=array("1"=>"111111","2"=>"bb","3"=>"cc","4"=>"bb");
$y1=array_keys($x,111111,true);//将不再返回数据(原数组里“111111”是字符串类型,而这里给的是数字类型)

报错是因为字符串要用单引号或双引号
$y1=array_keys($x,"bb",false);
$y2=array_keys($x,"bb",true);

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template