Skip to content

Instantly share code, notes, and snippets.

@thedustin
Created July 13, 2015 13:39
Show Gist options
  • Save thedustin/c286591cf7969410d58d to your computer and use it in GitHub Desktop.
Save thedustin/c286591cf7969410d58d to your computer and use it in GitHub Desktop.
A sort function which use a custom order
<?php
static $aTypesOrder = array(
'PDF', 'DOC', 'BMP', 'PSD', 'AI',
);
/**
* @param array $aAssetA
* @param array $aAssetB
*
* @return int
*/
function _sortByOwnOrder(array $aElementA, array $aElementB) {
global $aTypesOrder;
$iIndexA = array_search($aElementA['type'], $aTypesOrder);
$iIndexB = array_search($aElementB['type'], $aTypesOrder);
if($iIndexA === $iIndexB){
return 0;
} else if($iIndexA < $iIndexB){
return -1;
} else {
return 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment