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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jinkrish at gmail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed Sep 17 19:00:01 2025 UTC