php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77545 wrong output of array_diff
Submitted: 2019-01-30 08:20 UTC Modified: 2019-01-30 08:32 UTC
From: bostjan dot kristl at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
 [2019-01-30 08:20 UTC] bostjan dot kristl at gmail dot com
Description:
------------
I have tested in version Debian 9, PHP 7.0.33-0+deb9u1 and CentOS Linux release 7.6.1810, 7.2.14 


array_diff in first example show, that is no difference between arrays values

Test script:
---------------
$t1['c'] = 3;
$t1['i'] = 10;
$t1['iv'] = 10;

$t2['c'] = 3;
$t2['i'] = 10;
$t2['iv'] = 11;


var_dump(array_diff($t1,$t2));
var_dump(array_diff($t2,$t1));


Expected result:
----------------
array(1) {
  ["iv"]=>
  int(11)
}
array(1) {
  ["iv"]=>
  int(11)
}


Actual result:
--------------
array(0) {
}
array(1) {
  ["iv"]=>
  int(11)
}



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-01-30 08:32 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2019-01-30 08:32 UTC] requinix@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

http://php.net/manual/en/function.array-diff.php
> ...returns the values in array1 that are not present in any of the other arrays.

Perhaps you are looking for array_diff_assoc?
http://php.net/manual/en/function.array-diff-assoc.php
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 01 01:01:28 2024 UTC