Bug #73843 [NEW]: array_search return key is wrong

From: Date: Fri, 30 Dec 2016 09:05:53 +0000
Subject: Bug #73843 [NEW]: array_search return key is wrong
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-206236@lists.php.net to get a copy of this message
From: 376292871 at qq dot com Operating system: win7 sp1 64bit PHP version: 7.0Git-2016-12-30 (Git) Package: Arrays related Bug Type: Bug Bug description:array_search return key is wrong Description: ------------ --- From manual page: http://www.php.net/function.array-search --- Test script: --------------- $arr = [241, 248, 249, 250, 255, 256, 257]; $except = [248, 249, 255]; foreach ($except as $value) { if ($key = array_search($value, $arr) !== false) { unset($arr[$key]); } } print_r($arr); exit; Expected result: ---------------- Array ( [0] => 241 [3] => 250 [5] => 256 [6] => 257 ) Actual result: -------------- Array ( [0] => 241 [2] => 249 [3] => 250 [4] => 255 [5] => 256 [6] => 257 ) -- Edit bug report at https://bugs.php.net/bug.php?id=73843&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=73843&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=73843&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=73843&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=73843&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=73843&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=73843&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=73843&r=needscript Try newer version: https://bugs.php.net/fix.php?id=73843&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=73843&r=support Expected behavior: https://bugs.php.net/fix.php?id=73843&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=73843&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=73843&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=73843&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73843&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=73843&r=dst IIS Stability: https://bugs.php.net/fix.php?id=73843&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=73843&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=73843&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=73843&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=73843&r=mysqlcfg

« previous php.bugs (#206236) next »