|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-07-02 18:34 UTC] tomas at matfyz dot cz
Description:
------------
array_search() function finds non-existent element after array_slice() is used to slice the array.
tested on 5.2.0 and 5.2.5, don't have access to newer system.
Reproduce code:
---------------
$a["nazdar"] = "pozdrav";
$a["write"] = 1;
$a[2] = "ahoj";
$a = array_slice($a, 2);
$keys = array_keys($a);
echo "keys:\n"; var_dump($keys);
check_array_search("wrqwdite2", $keys);
function check_array_search($val, $keys)
{
$i = array_search($val, $keys);
if ($i === false) {
echo "OK\n";
return;
}
echo "BUG!!! Non-existent value \"$val\" found in keys at position $i!!!\n";
}
Expected result:
----------------
keys:
array(1) {
[0]=>
int(0)
}
OK
Actual result:
--------------
keys:
array(1) {
[0]=>
int(0)
}
BUG!!! Non-existent value "wrqwdite2" found in keys at position 0!!!
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Tue Jan 20 21:00:02 2026 UTC |
> array(1) { > [0]=> > int(0) > } 0 == 'any non-numeric string'