PHP 4.0 Bug #7194 Updated: array_intersect() changes element order

From: Date: Sat, 21 Oct 2000 18:28:22 +0000
Subject: PHP 4.0 Bug #7194 Updated: array_intersect() changes element order
Groups: php.dev 
Request: Send a blank email to php-dev+get-35733@lists.php.net to get a copy of this message
ID: 7194 Updated by: venaas Reported By: s.busch@billiton.de Status: Closed Bug Type: Feature/Change Request Assigned To: venaas Comments: I wanted array_intersect() for "sets" where order is not important, but I think you're right, it's good if the order is kept. I've now made both array_intersect() and array_diff() keep the order. Previous Comments: --------------------------------------------------------------------------- [2000-10-13 13:59:15] s.busch@billiton.de 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" } --------------------------------------------------------------------------- Full Bug description available at: http://bugs.php.net/?id=7194

« previous php.dev (#35733) next »