Req->Doc #73576 [Opn]: Create array_concat alias for array_merge
| From: | pollita@php.net | Date: | Thu, 18 May 2017 00:47:11 +0000 |
| Subject: | Req->Doc #73576 [Opn]: Create array_concat alias for array_merge | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-14701@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73576&edit=1
ID: 73576
Updated by: pollita@php.net
Reported by: ian at ianchanning dot com
Summary: Create array_concat alias for array_merge
Status: Open
-Type: Feature/Change Request
+Type: Documentation Problem
Package: Arrays related
Operating System: N/A
PHP Version: 5.6.28
Block user comment: N
Private report: N
New Comment:
This is more of a documentation issue IMO.
Some better wording on the manual pages of the array section may help out, but there's no need
to further pollute the global namespace with aliases.
Previous Comments:
------------------------------------------------------------------------
[2016-11-21 22:01:27] ian at ianchanning dot com
Description:
------------
There is no documented array concatenation function. This is a very common function, e.g. Javascript
and Ruby have the
concat function, Python has + and Haskell has
++.
The array_merge function (http://php.net/manual/en/function.array-merge.php) is what
has be used if you want to concatenate arrays. However it is not mentioned in the documentation (not
even in the comments) of that method that that is what should be used.
I propose that array_concat be created as an alias of array_merge. The
concatenation of an associative array is also consistent with trying to merge the hash maps. For
example this Stack Overflow question on [concatenating two
dictionaries](http://stackoverflow.com/questions/1781571/how-to-concatenate-two-dictionaries-to-create-a-new-one-in-python#1784128)
is marked as a duplicate of the function 'How to merge two Python dictionaries'. That is,
it is consistent that hash map concatenation is the same as hash map merging.
So I believe that array_concat is a perfect alias for array_merge in terms
of numeric arrays and a valid (albeit unnecessary) alias for associative arrays.
This will help almost all developers coming to PHP from other dynamic languages.
Test script:
---------------
<?php
var_dump(array_concat(array('London'), array('Calling')));
?>
Expected result:
----------------
array(2) {
[0]=>
string(6) "London"
[1]=>
string(7) "Calling"
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73576&edit=1