Re: [RFC Discussion] array_change_keys()
| From: | Côme Chilliet | Date: | Mon, 30 May 2016 03:17:00 +0000 |
| Subject: | Re: [RFC Discussion] array_change_keys() | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-93631@lists.php.net to get a copy of this message | ||
Le lundi 30 mai 2016, 01:40:21 Colin O'Dell a écrit :
> Marco,
>
>
> > 1. could you also provide the code for the benchmarks? I'd gladly measure
> > them with an accurate tool
> >
>
> Yeah that would be great! Here's the benchmark I was using:
> https://gist.github.com/colinodell/872c1f0c92351af687347c0c8be4f253’¾Ó
> G4®dH´QÅãm
>
>
> > 2. do we really need another array function that is basically an
> >
Attachment: [application/pgp-signature] This is a digitally signed message part. signature.asc
array_combine(array_map($someFunc, array_keys($arr)),
> > $arr)?
> >
>
> While array_combine() technically works, the callback does not have access
> to both the key AND value. Anyone needing access to both must currently
> resort to using a foreach loop (unless there's some other clever
> combination of functions that I'm missing).
Yes there is:
array_combine(
array_map($someFunc, array_keys($arr), $arr),
$arr
)
This way $someFunc gets key as first argument and value as second. (you might use array_values($arr)
instead of $arr but I’m not sure it’s worth it)
Côme
Attachment: [application/pgp-signature] This is a digitally signed message part. signature.asc