Skip to content

Instantly share code, notes, and snippets.

@monobasic
Created June 19, 2012 11:15
Show Gist options
  • Save monobasic/2953594 to your computer and use it in GitHub Desktop.
Save monobasic/2953594 to your computer and use it in GitHub Desktop.
<?php
function cmp($a, $b) {
$sortOrder = array(
'3/0', '2/0', '1/0', '1', '2', '3'
);
$sortOrderPositionA = array_shift(array_keys($sortOrder, $a['name']));
$sortOrderPositionB = array_shift(array_keys($sortOrder, $b['name']));
if ($sortOrderPositionA == $sortOrderPositionB) {
return 0;
}
return ($sortOrderPositionA < $sortOrderPositionB) ? -1 : 1;
}
$data = array(
'2/0' => array(
'name' => '2/0'
),
'3/0' => array(
'name' => '3/0'
),
'1/0' => array(
'name' => '1/0'
),
'3' => array(
'name' => '3'
),
'2' => array(
'name' => '2'
),
'1' => array(
'name' => '1'
)
);
var_dump('original:', $data);
$dataSorted = uasort($data, 'cmp');
var_dump('sorted:', $data);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment