php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69926 array_search returns incorrect values
Submitted: 2015-06-25 06:36 UTC Modified: 2015-06-25 06:38 UTC
From: jinkrish at gmail dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.6.10 OS: Ubuntu
Private report: No CVE-ID: None
 [2015-06-25 06:36 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-25 06:38 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2015-06-25 06:38 UTC] requinix@php.net
array_search() does a loose comparison by default. Use the third argument.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 22:01:31 2024 UTC