php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25164 array_diff issue
Submitted: 2003-08-20 02:06 UTC Modified: 2003-08-24 11:07 UTC
From: linuxfool at hotmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.3.2 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: linuxfool at hotmail dot com
New email:
PHP Version: OS:

 

 [2003-08-20 02:06 UTC] linuxfool at hotmail dot com
Description:
------------
See Code.

Thanks for your time.

Reproduce code:
---------------
echo "<pre>";
echo "RUNNING PHP VER 4.2.2 ON RH 9\n";

$array1 = array (1=>9,2=>10,3=>5,4=>54,5=>30,6=>1,7=>22,8=>22,9=>111,10=>110,11=>30);
$array2 = array (1=>9,2=>10,3=>5,4=>54,5=>30,6=>1,7=>22,8=>22,9=>111,10=>110,11=>112);
print_r($array1);
print_r($array2);

print_r(array_diff($array1,$array2));

echo "If the last value in array1 (30) is changed to anything other then 30(that i am aware of) array_diff  works right.\nHave I been smoking too much crack again?\n";


echo "</pre>";
?>


Expected result:
----------------
RUNNING PHP VER 4.2.2 ON RH 9
Array
(
    [1] => 9
    [2] => 10
    [3] => 5
    [4] => 54
    [5] => 30
    [6] => 1
    [7] => 22
    [8] => 22
    [9] => 111
    [10] => 110
    [11] => 30
)
Array
(
    [1] => 9
    [2] => 10
    [3] => 5
    [4] => 54
    [5] => 30
    [6] => 1
    [7] => 22
    [8] => 22
    [9] => 111
    [10] => 110
    [11] => 112
)
Array
(
[11] => 30
)
If the last value in array1 (30) is changed to anything other then 30(that i am aware of) it works right.
Have I been smoking too much crack again?



Actual result:
--------------
RUNNING PHP VER 4.2.2 ON RH 9
Array
(
    [1] => 9
    [2] => 10
    [3] => 5
    [4] => 54
    [5] => 30
    [6] => 1
    [7] => 22
    [8] => 22
    [9] => 111
    [10] => 110
    [11] => 30
)
Array
(
    [1] => 9
    [2] => 10
    [3] => 5
    [4] => 54
    [5] => 30
    [6] => 1
    [7] => 22
    [8] => 22
    [9] => 111
    [10] => 110
    [11] => 112
)
Array
(
)
If the last value in array1 (30) is changed to anything other then 30(that i am aware of) it works right.
Have I been smoking too much crack again?



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-08-24 11:03 UTC] sniper@php.net
Simpler script:

<?php

$array1 = array (2,2);
$array2 = array (1,2);
print_r($array1);
print_r($array2);

print_r(array_diff($array1,$array2));
?>

Output:

Array
(
    [0] => 2
    [1] => 2
)
Array
(
    [0] => 1
    [1] => 2
)
Array
(
)

 [2003-08-24 11:07 UTC] sniper@php.net
Actually this is bogus. From manual:

"array_diff() returns an array containing all the values of 
array1  that are not present in any of the other arguments."

In your example, 30 is present in the $array2.

 [2003-08-25 13:09 UTC] linuxfool at Hotmail dot com
Crack Prevails once again...
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 16 09:01:33 2025 UTC