【紧急】array_search的BUG么???!!
$callings = Array(
'uid' => '1372830817.235',
'duid' => '1372830817.236',
'channel' => 'SIP/8002-000000eb',
'destination' =>'SIP/68782389-000000ec',
'from_number' => 8002,
'to_number' => '051010086',
'switchboard' => 0,
'timer' => 1372830820,
'is_out' => 1,
'flag' => 1
);
echo array_search('SIP/8006-000000ed',$callings);结果竟然是switchboard?!
改成 echo array_search('SIP/8006-000000ed',$callings,TRUE);才成功
难道array_search默认情况下不能搜索字符串?!!
很诡异的问题,如果第九行的值改成不为0,就能正常了
只要值为0,就返回值为0对应的那个key,这个是BUG么??!!! 这算什么bug, php对字符串和数字进行比较时都会把字符串转换成数字类型的, 而"SIP/8006-000000ed"很明显会被转换成0, 所以就出现你的情况. If the third parameter strict is set to TRUE then the array_search() function will search for identical elements in the haystack. This means it will also check the types of the needle in the haystack, and objects must be the same instance. 回复 3# liexusong
我就不明白了,这串字符怎么样也不能被转换成0吧。。。
回复 4# maochanglu
这个字符串和0简直就是八竿子打不着的
再怎么低级也不会认为是0吧。。
回复 6# 除美灭日平韩
If the string starts with valid numeric data, this will be the value used. Otherwise, the value will be 0 (zero). 回复 7# maochanglu
只对以数字开头的字符串有效?
那这个函数有什么意义呢?
根据测测试,只要在搜到有个value值为0之前没有搜索到要查找的字符串,就会把这个0对应的key返回出来,不管后面有没有这个要搜索的字符串的值
比如$arr = array('aaa'=>'0d','bbbb'=>0,'ddd'=>'dd');
echo array_search('dd', $arr);还是输出bbbb
这不是BUG是什么?
如果非要加个true才能搜索出来
那为什么还要这第三个参数干嘛呢
直接默认就按照第三个参数是TRUE的情况搜索不就完了
想不明白 也不算bug吧,手册都有解释
如果不加 第三个参数,默认是FALSE,会把传入的值 intval 一下
你看看 echo intval('SIP/8006-000000ed'); 结果是0
如果可选的第三个参数 strict 为 TRUE,则 array_search() 还将在 haystack 中检查 needle 的类型。
所以 没有写明 为 true 的时候,是不检测类型的,都会 intval 的
页:
[1]
2