|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #73576 Create array_concat alias for array_merge
Submitted: 2016-11-21 22:01 UTC Modified: 2021-12-19 22:01 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: ian at ianchanning dot com Assigned: cmb (profile)
Status: Closed Package: Arrays related
PHP Version: 5.6.28 OS: N/A
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
47 - 46 = ?
Subscribe to this entry?

 [2016-11-21 22:01 UTC] ian at ianchanning dot com
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 this Stack Overflow question on [concatenating two dictionaries]( 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:
var_dump(array_concat(array('London'), array('Calling')));

Expected result:
array(2) {
  string(6) "London"
  string(7) "Calling"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-05-18 00:47 UTC]
-Type: Feature/Change Request +Type: Documentation Problem
 [2017-05-18 00:47 UTC]
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.
 [2018-07-15 23:42 UTC]
-Type: Documentation Problem +Type: Feature/Change Request
 [2021-12-15 17:19 UTC]
-Status: Open +Status: Feedback -Assigned To: +Assigned To: carusogabriel
 [2021-12-15 17:19 UTC]
The first sentence of the description is (emphasis mine):

| Merges the elements of one or more arrays together so that the
| values of one are *appended* to the end of the previous one.

"Append" is, in my opinion, even clearer than "concatenate".  I
don't see that the documentation could be improved here.

However, Gabriel changed this back to feature request.  Are you
suggesting we should actually introduce an alias for
 [2021-12-19 19:33 UTC]
-Status: Feedback +Status: Open -Assigned To: carusogabriel +Assigned To:
 [2021-12-19 19:33 UTC]
Not suggesting anything here, my bad changing the type of the bug
 [2021-12-19 22:01 UTC]
-Status: Open +Status: Closed -Type: Feature/Change Request +Type: Documentation Problem -Assigned To: +Assigned To: cmb
 [2021-12-19 22:01 UTC]
Okay, closing then per my comment above.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Tue Dec 06 07:04:07 2022 UTC