Doc #65555 [Opn->Fbk]: Example #1 seems to be incorrect.

From: Date: Mon, 26 Aug 2013 09:45:18 +0000
Subject: Doc #65555 [Opn->Fbk]: Example #1 seems to be incorrect.
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-10220@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=65555&edit=1

 ID:                 65555
 Updated by:         yohgaki@php.net
 Reported by:        bsasser at sindtech dot net
 Summary:            Example #1 seems to be incorrect.
-Status:             Open
+Status:             Feedback
 Type:               Documentation Problem
 Package:            Documentation problem
 Operating System:   n/a
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

I cannot understand problem.
What is your suggestion improving the doc?


Previous Comments:
------------------------------------------------------------------------
[2013-08-26 00:26:09] 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.


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



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


Thread (3 messages)

« previous php.doc.bugs (#10220) next »