PHP 4.0 Bug #7194: array_intersect() changes element order
| From: | s dot busch at billiton dot de | Date: | Fri, 13 Oct 2000 17:59:15 +0000 |
| Subject: | PHP 4.0 Bug #7194: array_intersect() changes element order | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-34943@lists.php.net to get a copy of this message | ||
From: s.busch@billiton.de
Operating system: linux (kernel 2.2.14)
PHP version: 4.0.2
PHP Bug Type: Feature/Change Request
Bug description: array_intersect() changes element order
The function array_intersect() does change the order of the elements
that are returned from array in first parameter. Since "order" is an essential feature of
arrays it would be inconsistent to change it implicitely. Seems to be weak implementation of
array_intersect().
(At least it should be documented, but i think it should be fixed)
I don't checked the other array-functions for this behavior, it could be that some show this
inconsistency, too.
The resulting array seems to be in order of the contained values. In my example, the resulting array
is alphabetically sorted:
---- code snippet ----
// result of array_intersect() is ex
$a = array(1=>'c',2=>'z',666=>'b',4=>'a');
$b = $a;
var_dump(array_intersect($a,$b));
---- result ----
array(4) {
[4]=>
string(1) "a"
[666]=>
string(1) "b"
[1]=>
string(1) "c"
[2]=>
string(1) "z"
}
--
Edit Bug report at: http://bugs.php.net/?id=7194&edit=1