Sort an array according to another array as a priority list


$customer['address'] = '123 fake st';
$customer['name'] = 'Tim';
$customer['dob'] = '12/08/1986';
$customer['dontSortMe'] = 'this value doesnt need to be sorted';

$customerSorted = array_replace(array_flip(array('name', 'dob', 'address')), $customer);

//Result:

//Array (
//  [name] => Tim
//  [dob] => 12/08/1986
//  [address] => 123 fake st
//  [dontSortMe] => this value doesnt need to be sorted
//)

Comments

Leave a Reply