|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-12-21 11:40 UTC] willem at fkkc dot nl
Description:
------------
array_search returns incorrect position-value when an array is modified with array_push or array_unshift
Reproduce code:
---------------
$array = array('a1','b2','c3');
array_unshift($array,'d4');
$pos = array_search('d4');
if($pos === FALSE){
print implode(',',$array);
}else{
print 'Position = '.$pos;
}
Expected result:
----------------
Position = 0
Actual result:
--------------
d4,a1,b2,c3
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 18:00:01 2025 UTC |
I'm sorry for the typo in the reproduce-code, here's a correct one. $array = array('a1','b2','c3'); array_unshift($array,'d4'); $pos = array_search('d4',$array); if($pos === FALSE){ print implode(',',$array); }else{ print 'Position = '.$pos; } I've re-opened the bug-report because it's not a bogus to my opninion. The code worked fine in php 5.1.4, in php 5.2 not anymore. The only work-around to fix the problem was to implode the array and use regular expressions to check if the value is there.