php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78164 array_diff_key won't return diff while it shoud in a very specific case
Submitted: 2019-06-14 15:56 UTC Modified: 2019-06-14 16:04 UTC
From: joseph42379 at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.1Git-2019-06-14 (snap) OS: Mac 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: joseph42379 at gmail dot com
New email:
PHP Version: OS:

 

 [2019-06-14 15:56 UTC] joseph42379 at gmail dot com
Description:
------------
Turns out if the first argument(array) provided is smaller than the second one, it always return the empty array.

Test script:
---------------
<?
var_dump(
        array_diff_key(
            [
                'a'=>1,
            ], 
            [
                'a'=>1,
                'b'=>1
            ]
        )
    );

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

Actual result:
--------------
array(0) { }

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-06-14 16:04 UTC] requinix@php.net
-Status: Open +Status: Not a bug -Package: Unknown/Other Function +Package: *General Issues
 [2019-06-14 16:04 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

https://www.php.net/manual/en/function.array-diff-key.php
> Compares the keys from array1 against the keys from array2 and returns the difference. This function is like
> array_diff() except the comparison is done on the keys instead of the values.

> Returns an array containing all the entries from array1 whose keys are absent from all of the other arrays.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 04 00:01:36 2025 UTC