Bug #69926 [Opn->Nab]: array_search returns incorrect values
| From: | requinix@php.net | Date: | Thu, 25 Jun 2015 06:38:58 +0000 |
| Subject: | Bug #69926 [Opn->Nab]: array_search returns incorrect values | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-193864@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=69926&edit=1
ID: 69926
Updated by: requinix@php.net
Reported by: jinkrish at gmail dot com
Summary: array_search returns incorrect values
-Status: Open
+Status: Not a bug
Type: Bug
Package: Arrays related
Operating System: Ubuntu
PHP Version: 5.6.10
Block user comment: N
Private report: N
New Comment:
array_search() does a loose comparison by default. Use the third argument.
Previous Comments:
------------------------------------------------------------------------
[2015-06-25 06:36:59] jinkrish at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.array-search
---
$arr = [
'photos' => 1,
'floorplan' => 2,
'3dfloorplan' => 3,
'video' => 4,
'currentstatus' => 5,
'rooms' => 6,
'locationmap' => 7,
1 => 'photos',
2 => 'floorplan',
3 => '3dfloorplan',
4 => 'video',
5 => 'currentstatus',
6 => 'rooms',
7 => 'locationmap',
8 => 'brochure',
];
$res = array_search('3dfloorplan',$arr);
//$res is
// '3dfloorplan
//but my expectation is 3
Test script:
---------------
$arr = [
'photos' => 1,
'floorplan' => 2,
'3dfloorplan' => 3,
'video' => 4,
'currentstatus' => 5,
'rooms' => 6,
'locationmap' => 7,
1 => 'photos',
2 => 'floorplan',
3 => '3dfloorplan',
4 => 'video',
5 => 'currentstatus',
6 => 'rooms',
7 => 'locationmap',
8 => 'brochure',
];
$res = array_search('3dfloorplan',$arr);
//$res is
// '3dfloorplan
//but my expectation is 3
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69926&edit=1