Re: 4.3.3-RC1 => possible bug in in_array()?
| From: | Marek Kilimajer | Date: | Fri, 25 Jul 2003 12:52:44 +0000 |
| Subject: | Re: 4.3.3-RC1 => possible bug in in_array()? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-156842@lists.php.net to get a copy of this message | ||
in_array searches for a value, you suply key. This will work as you expect:
$data = array();
foreach ($this->_array_a as $key => $value) {
if (! in_array($value, $this->_array_b)
$data['added'][$key] = $this->_array_a[$key];
}
Branko F. Grac(nar wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi. I've just found weird thing about in_array() function. Platform: FreeBSD 5.1/PHP 4.3.3-RC1 Consider this code: $this->_array_a and $this->_array_b ARE IDENTICAL $data = array(); foreach ($this->_array_a as $key => $value) { if (! in_array($key, $this->_array_b) $data['added'][$key] = $this->_array_a[$key]; } Therefore after execution $data should be empty. But there is whole $this->_array_a in $data after execution... The following code works ($data is empty after execution): foreach ($this->_array_a as $key => $value) { if (! isset($this->_array_b[$key])) $data['added'][$key] = $this->_array_a[$key]; } Why is this happening? Brane -----BEGIN PGP SIGNATURE----- iD8DBQE/ISOGfiC/E+t8hPcRAll7AJ9EbH6FwwJC/vjsBNG3qMWvWVdmbQCggILs UvLwPdDkKk2UrXxpPo6vF5M= =OqAg -----END PGP SIGNATURE-----