Skip to content

Instantly share code, notes, and snippets.

@wpscholar
Created February 11, 2014 17:26
Show Gist options
  • Save wpscholar/8939632 to your computer and use it in GitHub Desktop.
Save wpscholar/8939632 to your computer and use it in GitHub Desktop.
Order an array based an ordered set of keys. NOTE: Values that don't have a corresponding key in the array of keys will be dropped.
<?php
/**
* Order an array based an ordered set of keys.
* NOTE: Values that don't have a corresponding key in the array of keys will be dropped.
*
* @param array $array
* @param array $keys
* @return array
*/
public static function array_order_by_keys( array $array, array $keys ) {
$ordered = array();
foreach ( $keys as $key ) {
$ordered[$key] = $array[$key];
}
return $ordered;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment