#31927 [Opn->Bgs]: in_array() not working with array containing strings as needle

From: Date: Sun, 13 Feb 2005 20:26:50 +0000
Subject: #31927 [Opn->Bgs]: in_array() not working with array containing strings as needle
References: 1  Groups: php.doc 
Request: Send a blank email to phpdoc+get-969366559@lists.php.net to get a copy of this message
ID: 31927 Updated by: vrana@php.net Reported By: bart at mediawave dot nl -Status: Open +Status: Bogus Bug Type: Documentation problem Operating System: WinXP PHP Version: 5CVS-2005-02-11 (dev) New Comment: No bug here. Previous Comments: ------------------------------------------------------------------------ [2005-02-12 22:32:37] tony2001@php.net Well, probably this should be clarified in the docs. But the current description looks rather clear to me, though. Reclassifying as docu problem. ------------------------------------------------------------------------ [2005-02-12 22:22:18] bart at mediawave dot nl You are right. It isn't a bug. in_array was apparently designed to work this way and does so properly. Maybe we should change this to a change/feature request then? Or otherwise a documentation problem? It simply isn't intuitive for people now. This is my last attempt. I won't be re-opening this bug anymore. ------------------------------------------------------------------------ [2005-02-12 14:45:49] tony2001@php.net >An array itself isn't a value. Nope. Don't know who told you this, but he/she was definitely wrong. >So, one would expect that in_array checks if all these >"values" exist in the haystack. No, see examples in the docs. No bug here. ------------------------------------------------------------------------ [2005-02-12 01:16:38] bart at mediawave dot nl The documentation clearly states: in_array -- Checks if a "value" exists in an array It doesn't say: in_array -- Checks if a "variable" exists in an array An array itself isn't a value. It's a variable containing a collection of values. So, one would expect that in_array checks if all these "values" exist in the haystack. (Regardless of the containing variable type/structure) It shouldn't check if a variable exists in the haystack. The exact match behaviour in your example should only happen when the parameter strict is set. (In my opinion at least) ------------------------------------------------------------------------ [2005-02-11 20:52:14] tony2001@php.net No bug here: in_array() looks for exact match. This code works fine: <?php $a = array(array("NT", "Linux"), array("Irix", "Linux"), "OS2"); if (in_array(array("NT", "Linux"), $a)) { echo "NT Linux found\n"; } ?> ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/31927 -- Edit this bug report at http://bugs.php.net/?id=31927&edit=1

« previous php.doc (#969366559) next »