Edit report at https://bugs.php.net/bug.php?id=62497&edit=1
ID: 62497
User updated by: martin at psinas dot com
Reported by: martin at psinas dot com
Summary: array_intersect doesn't work properly when data is
reversed with duplicates
-Status: Open
+Status: Closed
Type: Bug
Package: Arrays related
Operating System: Linux
PHP Version: 5.4.4
Block user comment: N
Private report: N
New Comment:
not a bug.
Previous Comments:
------------------------------------------------------------------------
[2012-07-06 22:30:27] martin at psinas dot com
Description:
------------
As mentioned here:
http://us3.php.net/manual/en/function.array-intersect.php#92900
array_intersect doesn't work properly when data is reversed with duplicates
Test script:
---------------
<?php
$text1 = "one two two";
$text2 = "one two three";
$old = explode(' ', $text1);
$new = explode(' ', $text2);
$preserved1 = array_intersect($old, $new);
$deleted = array_diff($old, $preserved1);
$preserved2 = array_intersect($new, $old);
$inserted = array_diff($new, $preserved2);
echo '<pre>';
print_r($preserved1);
print_r($deleted);
print_r($preserved2);
print_r($inserted);
echo '<pre>';
?>
Expected result:
----------------
Array
(
[0] => one
[1] => two
)
Array
(
[2] => three
)
Array
(
[0] => one
[1] => two
)
Array
(
[2] => three
)
Actual result:
--------------
Array
(
[0] => one
[1] => two
[2] => two
)
Array
(
)
Array
(
[0] => one
[1] => two
)
Array
(
[2] => three
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62497&edit=1