Doc #79402 [Opn->Fbk]: Description fix suggestion
| From: | cmb@php.net | Date: | Sun, 22 Mar 2020 13:37:08 +0000 |
| Subject: | Doc #79402 [Opn->Fbk]: Description fix suggestion | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-17441@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79402&edit=1
ID: 79402
Updated by: cmb@php.net
Reported by: simongcc at gmail dot com
Summary: Description fix suggestion
-Status: Open
+Status: Feedback
Type: Documentation Problem
Package: Documentation problem
PHP Version: Irrelevant
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Isn't that already sufficiently explained:
| The + operator returns the right-hand array appended to the
| left-hand array; for keys that exist in both arrays, the elements
| from the left-hand array will be used, and the matching elements
| from the right-hand array will be ignored.
Previous Comments:
------------------------------------------------------------------------
[2020-03-22 00:40:32] simongcc at gmail dot com
Description:
------------
---
From manual page: https://php.net/language.operators.array
---
It is only a problem in description.
In the docs, it states that $a + $b is Union and it is Union of $a and $b.
But it is not completely reflecting the characteristic of the Union in PHP.
Since strictly speaking, an Union should be mutually inclusive of different things.
In PHP, it is only an union of key regardless of value.
So it should be written as
Union of the key in $a and $b and based on $a or vice versa if it is $b + $a. (Because when there
is/are key(s) exist(s) in the first variable, the same key(s) in the second variable will be
ignored)
Test script:
---------------
$a = array('something' => 'interesting', 2);
$b = array('another' => 'interesting thing', 0 => 3);
$c = $a + $b;
$d = $b + $a;
print_r($c);
print_r($d);
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79402&edit=1