简体   繁体   中英

How can I sort a php associative array according to another array with the same key value

To make my question easier to understand, I will give an example output.

var_dump output:

Array 1:

array(22) { ["#HIDDEN_ID"]=> string(10) "08/11/2013"

Array 2:

array(22) { ["#HIDDEN_ID"]=> string(96) "www.google.co.uk....."

Array one is sorted by most recent date, however my second array is not but it has the same file ids.

Therefore I would like to sort my second array to how my first arrays file ids are stored.

I have no clue how to do this using uasort or usort.

Any help would be greatly appreciated!

$keys = array_keys($array1);

array_multisort($keys, SORT_ASC, $array2);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM