Joe
Joe

Reputation: 275

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.

Upvotes: -1

Views: 76

Answers (1)

Skylervich
Skylervich

Reputation: 150

$keys = array_keys($array1);

array_multisort($keys, SORT_ASC, $array2);

Upvotes: 1

Related Questions