Bug #73843 [Opn]: array_search return key is wrong
| From: | 376292871 at qq dot com | Date: | Fri, 30 Dec 2016 10:26:24 +0000 |
| Subject: | Bug #73843 [Opn]: array_search return key is wrong | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-206237@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73843&edit=1
ID: 73843
User updated by: 376292871 at qq dot com
Reported by: 376292871 at qq dot com
Summary: array_search return key is wrong
Status: Open
Type: Bug
Package: Arrays related
-Operating System: win7 sp1 64bit
+Operating System: win10 64bit
PHP Version: 7.0Git-2016-12-30 (Git)
Block user comment: N
Private report: N
New Comment:
update OS
Previous Comments:
------------------------------------------------------------------------
[2016-12-30 09:05:52] 376292871 at qq dot com
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 this bug report at https://bugs.php.net/bug.php?id=73843&edit=1