Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save 63phc/75122f4d160d0320d2bdac855b21bed2 to your computer and use it in GitHub Desktop.
Save 63phc/75122f4d160d0320d2bdac855b21bed2 to your computer and use it in GitHub Desktop.
/**
* Сортирует массив по значениям ключей
*
* @param $array array Сортируемый массив
* @param $sortArray array Массив упорядоченных ключей
*/
private function sortArrayByKeyValues(&$array, $sortArray)
{
$tmpArray = [];
$sortArray = array_merge($sortArray, array_diff(array_keys($array), $sortArray));
foreach ($sortArray as $positionValue) {
if (isset($array[$positionValue])) {
$tmpArray[$positionValue] = $array[$positionValue];
}
}
$array = $tmpArray;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment