php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #65555 Example #1 seems to be incorrect.
Submitted: 2013-08-26 00:26 UTC Modified: 2013-10-15 11:54 UTC
From: bsasser at sindtech dot net Assigned:
Status: No Feedback Package: Documentation problem
PHP Version: Irrelevant OS: n/a
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2013-08-26 00:26 UTC] bsasser at sindtech dot net
Description:
------------
---
From manual page: http://www.php.net/function.array-diff-key#refsect1-function.array-diff-key-examples
---
Example #1 *appears* incorrect (based on my own ignorance).

The description of 'array_diff_keys' is written in simple enough English I *should* be able to see it the way you do (sorry, but I don't).  I must have missed something.

Test script:
---------------
Your example:
$array1 = array('blue'  => 1, 'red'  => 2, 'green'  => 3, 'purple' => 4);
$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan'   => 8);

var_dump(array_diff_key($array1, $array2));

Expected result:
----------------
I expected 'purple' to be included in the output because the function "Compares the keys from array1 against the keys from array2 and returns the difference."

Reading the Return Values portion of the function definition:
"Returns an array containing all the entries from array1 whose keys are not present in any of the other arrays."

'purple' is included in $array1, but not $array2 - thus a difference.

'cyan' and 'yellow', though technically a 'difference', are not in $array1 and therefore should not be returned based on the documentation.


Actual result:
--------------
Actual results are identical to those shown in your example #1.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-08-26 09:45 UTC] yohgaki@php.net
-Status: Open +Status: Feedback
 [2013-08-26 09:45 UTC] yohgaki@php.net
I cannot understand problem.
What is your suggestion improving the doc?
 [2013-10-15 11:54 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 03:01:20 2019 UTC