Req #66435 [Com]: Suggestion: Preserve original index in function array_column()
| From: | ramsey@php.net | Date: | Fri, 05 Dec 2014 16:09:08 +0000 |
| Subject: | Req #66435 [Com]: Suggestion: Preserve original index in function array_column() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-188938@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66435&edit=1
ID: 66435
Comment by: ramsey@php.net
Reported by: djot at hotmail dot com
Summary: Suggestion: Preserve original index in function
array_column()
Status: Assigned
Type: Feature/Change Request
Package: Arrays related
PHP Version: Irrelevant
Assigned To: ramsey
Block user comment: N
Private report: N
New Comment:
See also discussion here on the userland polyfill for array_column():
https://github.com/ramsey/array_column/issues/3
Previous Comments:
------------------------------------------------------------------------
[2014-01-07 14:57:45] djot at hotmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.array-column
---
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');
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66435&edit=1