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: -
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:
Status: Open Package: Arrays related
PHP Version: Irrelevant OS: linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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); });
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Mar 26 22:01:26 2019 UTC