php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #60485 in_array insensitive string comparison
Submitted: 2011-12-09 16:48 UTC Modified: 2021-06-25 11:56 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: Hast4656 at gmail dot com Assigned: cmb (profile)
Status: Wont fix Package: Arrays related
PHP Version: Irrelevant OS: linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: Hast4656 at gmail dot com
New email:
PHP Version: OS:

 

 [2011-12-09 16:48 UTC] Hast4656 at gmail dot com
Description:
------------
Can you please add parameter for in_array that let this function to compare 
strings insensitive?

Test script:
---------------
// something like
in_array('a', Array('a', 'A'), true, true);


// 4th bool param says should the function compare string in a case-sensitive manner or not


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-12-14 18:01 UTC] ppadron@php.net
Since in_array() handles different types, I don't think it would make sense to 
add a parameter that is exclusive to handling strings.
 [2011-12-30 04:19 UTC] phristen at yahoo dot com
How about adding a comparitor callback then?
Maybe even overload the third argument (e.g. if it's not a boolean, then assume callback), so we can do something like:

in_array('a', array('A', 'b'), function($a, $b) { return !strcasecmp($a, $b); });
 [2021-06-25 11:56 UTC] cmb@php.net
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: cmb
 [2021-06-25 11:56 UTC] cmb@php.net
This is unlikely to be implemented; a more general solution, i.e.
a function any() or some() has a better chance, but still would
need an RFC[1].

[1] <https://wiki.php.net/rfc/howto>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 15:01:29 2024 UTC