array_column icon indicating copy to clipboard operation
array_column copied to clipboard

Return original index

Open sagikazarmark opened this issue 10 years ago • 6 comments

It would be great if the function could return the original index of the row.

Example:

$array = array(
    'key' => array(
        'element' => 'value'
    )
);

// Returns array('key' => 'value')
array_column($array, 'element', true);

I know it only mimics the core function, but still would be a great feature.

sagikazarmark avatar May 05 '14 12:05 sagikazarmark

Thanks for the recommendation. I don't disagree with this feature, but it was discussed and decided not to include it in core PHP. Since this library is intended to maintain parity with core, I won't be adding it here, unless it gets added to core.

See here for reference:

  • https://github.com/php/php-src/pull/331
  • http://grokbase.com/t/php/php-internals/134pjar0re/functionality-updates-to-array-column

ramsey avatar May 08 '14 19:05 ramsey

IMO the referenced discussion is mostly against the other two features. The first feature could still be merged.

Only thing I would modify: The third param should be true to use the original index, so you have the opportunity to get a reindexed array.

Do you see any chance of it?

sagikazarmark avatar May 08 '14 19:05 sagikazarmark

I'll reopen this and give it some thought. If I do it, I'll need to get it accepted into core first, and then add it here, but it will put users in an odd state, since the functionality won't exist in 5.5, while it exists in this library, which they can't use if they're using 5.5.

ramsey avatar May 08 '14 20:05 ramsey

I think it makes sense to maintain a separate version for all PHP versions if the core changes. However it is also harder.

sagikazarmark avatar Dec 04 '14 22:12 sagikazarmark

Is this the functionality you're asking for?

https://bugs.php.net/bug.php?id=66435

ramsey avatar Dec 05 '14 16:12 ramsey

I am unable to fully understand that request. However, if I understand it well then it does not make sense.

What I would like is the following:

$arr = [
    'key' => [
        'foo' => 'bar',
    ],
];

// returns ['key' => 'bar']
array_column($arr, 'foo', true?);

sagikazarmark avatar Dec 05 '14 16:12 sagikazarmark