# The most efficicient way to pick key,value from a large array

- Thread: https://externals.io/message/86740
- Original archive: https://news-web.php.net/php.internals/86740
- Started by Netroby on 2015-06-18T01:24:20+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #86740 — Netroby — 2015-06-18T01:24:20+00:00

URL: https://externals.io/message/86740#86740

Now, we have a large array, contains user profile.
[uid, username, password, email, qq, msn, skype, address, zipcode,
telphone, mobile.......]

We need to pick information from this big array, and we know the key
we want to pick.
What's the efficient way ? Is there any function like

$pending_pick_key1 = [uid, username];
array_pick($origin_array,  $pending_pick_key1);  //return array
contains [uid, username]

$pending_pick_key2 = [username, password];
array_pick($origin_array, $pending_pick_key2); //return array contains
[username, password]


we current using array_filter and pass function into it to do this job.
But it's not fast as we test.

Any other ideas beside array_filter?

Or we have to implement an php extension to do this job ?

Sorry for trouble you. need your help.


Appreciate your time.
----------------------------
Netroby

---

## #86741 — Ryan Pallas — 2015-06-18T01:40:51+00:00

URL: https://externals.io/message/86740#86741 · In reply to: #86740

Use array_intersect_key with array_flip.

$pending_pick_key1 = [uid, username];
array_intersect_key($origin_array, array_flip( $pending_pick_key1));


> Now, we have a large array, contains user profile.
> [uid, username, password, email, qq, msn, skype, address, zipcode,
> telphone, mobile.......]
>
> We need to pick information from this big array, and we know the key
> we want to pick.
> What's the efficient way ? Is there any function like
>
> $pending_pick_key1 = [uid, username];
> array_pick($origin_array,  $pending_pick_key1);  //return array
> contains [uid, username]
>
> $pending_pick_key2 = [username, password];
> array_pick($origin_array, $pending_pick_key2); //return array contains
> [username, password]
>
>
> we current using array_filter and pass function into it to do this job.
> But it's not fast as we test.
>
> Any other ideas beside array_filter?
>
> Or we have to implement an php extension to do this job ?
>
> Sorry for trouble you. need your help.
>
>
> Appreciate your time.
> ----------------------------
> Netroby
