note 121750 deleted from function.array-merge by salathe
| From: | salathe@php.net | Date: | Mon, 06 Sep 2021 22:43:42 +0000 |
| Subject: | note 121750 deleted from function.array-merge by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-216879@lists.php.net to get a copy of this message | ||
Note Submitter: ian_channing at hotmail dot com
----
array_merge is the equivalent of concat in other languages. I tried to submit a bug that
array_concat should be created as an alias to this but it was rejected on the basis they didn't
want to polute the namespace and that the documentation should be updated instead. So here's
what I put in the bug #73576:
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 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 there is a Stack Overflow question on 'concatenating two dictionaries' that 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.