Req #60485 [Com]: in_array insensitive string comparison

From: Date: Fri, 30 Dec 2011 04:19:32 +0000
Subject: Req #60485 [Com]: in_array insensitive string comparison
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-166139@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=60485&edit=1

 ID:                 60485
 Comment by:         phristen at yahoo dot com
 Reported by:        Hast4656 at gmail dot com
 Summary:            in_array insensitive string comparison
 Status:             Open
 Type:               Feature/Change Request
 Package:            Arrays related
 Operating System:   linux
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

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); });


Previous Comments:
------------------------------------------------------------------------
[2011-12-14 18:01:34] 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-09 16:48:11] 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



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=60485&edit=1


Thread (4 messages)

« previous php.bugs (#166139) next »