#31927 [Bgs->Opn]: in_array() not working with array containing strings as needle
| From: | bart at mediawave dot nl | Date: | Sat, 12 Feb 2005 00:16:39 +0000 |
| Subject: | #31927 [Bgs->Opn]: in_array() not working with array containing strings as needle | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-73915@lists.php.net to get a copy of this message | ||
ID: 31927
User updated by: bart at mediawave dot nl
Reported By: bart at mediawave dot nl
-Status: Bogus
+Status: Open
Bug Type: Arrays related
Operating System: WinXP
PHP Version: 5CVS-2005-02-11 (dev)
New Comment:
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)
Previous Comments:
------------------------------------------------------------------------
[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";
}
?>
------------------------------------------------------------------------
[2005-02-11 05:53:04] bart at mediawave dot nl
Description:
------------
in_array() doesn't work with an array containing strings (larger then
one character) as a needle.
Reproduce code:
---------------
<?php
$a = array(array("Mac", "NT"), array("Irix", "Linux"),
"OS2");
if (in_array(array("NT", "Linux"), $a)) {
echo "NT Linux found\n";
}
if (in_array(array("XP", "Unix"), $a)) {
echo "XP Unix found\n";
}
if (in_array("OS2", $a)) {
echo "OS2 found\n";
}
?>
Expected result:
----------------
NT Linux found
OS2 found
Actual result:
--------------
OS2 found
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=31927&edit=1