Bug #62497 [NEW]: array_intersect doesn't work properly when data is reversed with duplicates
| From: | martin at psinas dot com | Date: | Fri, 06 Jul 2012 22:30:27 +0000 |
| Subject: | Bug #62497 [NEW]: array_intersect doesn't work properly when data is reversed with duplicates | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-171776@lists.php.net to get a copy of this message | ||
From: martin at psinas dot com
Operating system: Linux
PHP version: 5.4.4
Package: Arrays related
Bug Type: Bug
Bug description:array_intersect doesn't work properly when data is reversed with duplicates
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 bug report at https://bugs.php.net/bug.php?id=62497&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=62497&r=trysnapshot54
Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=62497&r=trysnapshot53
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=62497&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=62497&r=fixed
Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=62497&r=needdocs
Fixed in release: https://bugs.php.net/fix.php?id=62497&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=62497&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=62497&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=62497&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=62497&r=support
Expected behavior: https://bugs.php.net/fix.php?id=62497&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=62497&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=62497&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=62497&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=62497&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=62497&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=62497&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=62497&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=62497&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=62497&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=62497&r=mysqlcfg