Req #66435 [NEW]: Suggestion: Preserve original index in function array_column()

From: Date: Tue, 07 Jan 2014 14:57:46 +0000
Subject: Req #66435 [NEW]: Suggestion: Preserve original index in function array_column()
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-183625@lists.php.net to get a copy of this message
From:             djot at hotmail dot com
Operating system: 
PHP version:      Irrelevant
Package:          Arrays related
Bug Type:         Feature/Change Request
Bug description:Suggestion: Preserve original index in function array_column()

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 bug report at https://bugs.php.net/bug.php?id=66435&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=66435&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=66435&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=66435&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=66435&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=66435&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=66435&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=66435&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=66435&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=66435&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=66435&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=66435&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=66435&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=66435&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66435&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=66435&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=66435&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=66435&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=66435&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=66435&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=66435&r=mysqlcfg



Thread (5 messages)

« previous php.bugs (#183625) next »