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:
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.
Previous Comments:
------------------------------------------------------------------------
[2005-02-12 14:45:49] [EMAIL PROTECTED]
>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] [EMAIL PROTECTED]
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