|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #66435 Suggestion: Preserve original index in function array_column()
Submitted: 2014-01-07 14:57 UTC Modified: 2017-07-23 14:47 UTC
Avg. Score:4.0 ± 0.6
Reproduced:5 of 5 (100.0%)
Same Version:4 (80.0%)
Same OS:2 (40.0%)
From: djot at hotmail dot com Assigned: ramsey (profile)
Status: Wont fix Package: Arrays related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: djot at hotmail dot com
New email:
PHP Version: OS:


 [2014-01-07 14:57 UTC] djot at hotmail dot com
From manual page:
PHP v5.5.0 and above

Assuming you have an ARRAY like this, you cannot preserve 'original_index':
$arr['original_index'] = ARRAY('new_index'=>'foo', 'value'=>'bar');

// => results in lost original_index:
$arr = array_column($arr, NULL, 'new_index');
$arr['foo'] = ARRAY('new_index'=>'foo', 'value'=>'bar');

Suggestion: Option, to preserve original index:

array array_column ( array $array , mixed $column_key [, mixed $index_key = null ] [, mixed $column_index_original] )

// => "Push" original index as column 'old_index' to the ARRAY.
$arr = array_column($arr, NULL, 'new_index', 'old_index');
$arr['foo'] = ARRAY('new_index'=>'foo', 'value'=>'bar', 'old_index'=>'original_index');


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-12-05 16:08 UTC]
-Assigned To: +Assigned To: ramsey
 [2014-12-05 16:09 UTC]
See also discussion here on the userland polyfill for array_column():
 [2015-11-22 21:28 UTC] ww dot galen at gmail dot com
During the vote discussion (, Peter Cowburn suggested the 3rd parameter also take a bool, with `TRUE` meaning preserve keys and `FALSE` meaning re-key. This achieves the desired behavior without adding an argument. Here's the breakdown from his post:

> So the idea is to potentially change the $indexKey parameter from
string|int to bool|string|int where:
> - false => same as null or not using the argument: uses 0-based keys
(as RFC currently does)
> - true => uses keys from $input (suggested addition)
> - int|string => uses sub-array's $indexKey'th value as key (or 0-based
for missing value, as RFC currently does)
 [2017-07-23 14:47 UTC]
-Status: Assigned +Status: Wont fix
 [2017-07-23 14:47 UTC]
This has been sitting around forever. Any change would break existing expected behavior, so closing.
 [2017-08-11 20:13 UTC] ww dot galen at gmail dot com
At least two designs, adding a parameter and expanding the domain of the `$index_key` parameter, shouldn't break existing behavior.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jul 25 13:01:28 2024 UTC