Edit report at https://bugs.php.net/bug.php?id=60932&edit=1

 ID:                 60932
 Updated by:         johan...@php.net
 Reported by:        rupertrutland at gmail dot com
 Summary:            array_diff_assoc not working as expected.
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            *General Issues
 Operating System:   MAC OSX 10.6.8
 PHP Version:        5.3.9
 Block user comment: N
 Private report:     N

 New Comment:

The issue is in your array definition:

$arrayAssoc2 = array(
        'one' => '1: some val',
/*...*/
        'one' => '2: some val',
/*...*/
);

so you're overwriting the key 'one' again. If you replace the second 'one' with 
'four' it works as you expect.


Previous Comments:
------------------------------------------------------------------------
[2012-01-30 07:06:50] rupertrutland at gmail dot com

Description:
------------
The first key/value pair should, in theory, not be present in the result array.

Test script:
---------------
$arrayAssoc1 = array(
        'one' => '1: some val',
        'two' => '1: another val',
        'three' => '1: and another val',
        'four' => '1: fourth val',
        'five' => '1: fifth val',
        'six' => '1: sixth param',
        'seven' => '1: sixth param',
        'starwars' => '2: lightsaber'
);
$arrayAssoc2 = array(
        'one' => '1: some val',
        'two' => '1: another val',
        'three' => '1: and another val',
        'one' => '2: some val',
        'five' => '1: fifth val',
        'three' => '2: and another val',
        'seven' => '2: and another val',
        'starwars' => '2: lightsaber'
);
var_dump(array_diff_assoc($arrayAssoc1, $arrayAssoc2));

Expected result:
----------------
array(5) {
  ["three"] => string(18) "1: and another val"
  ["four"] => string(13) "1: fourth val"
  ["six"] => string(14) "1: sixth param"
  ["seven"] => string(14) "1: sixth param"
}

Actual result:
--------------
array(5) {
  ["one"] => string(11) "1: some val"
  ["three"] => string(18) "1: and another val"
  ["four"] => string(13) "1: fourth val"
  ["six"] => string(14) "1: sixth param"
  ["seven"] => string(14) "1: sixth param"
}


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=60932&edit=1

Reply via email to