-
-
Save jimboobrien/c8c4b44bd73a9572f07ff0df71fd306e 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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