-
Notifications
You must be signed in to change notification settings - Fork 0
A wrapper for array_column that maintains the keys of the original array.
License
djmattyg007/array_column_maintain_keys
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
array_column_maintain_keys() is a wrapper for the array_column() function introduced in PHP 5.5 (or usable in 5.3 and 5.4 via the recommended userland polyfill, see link below). The default behaviour of array_column() is to trash the keys from the top-level input array, and instead return a numerically-indexed array. You can optionally pass it the name of a second key in the sub-arrays of the input array, and have it use the values of those keys for the keys of the return array instead. Unfortunately, there is no option to have it use the keys of the top-level input array. This wrapper function, which also uses array_combine() and array_keys(), resolves that problem quite nicely. See here for the recommended userlannd polyfill of array_column(): https://github.com/ramsey/array_column This software is released into the public domain without any warranty.
About
A wrapper for array_column that maintains the keys of the original array.