Last active
August 29, 2015 14:14
-
-
Save jk/fd0fc583384a58fd4816 to your computer and use it in GitHub Desktop.
This file contains 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 | |
$list = []; | |
$keys = ['a', 'x']; | |
foreach ($keys as $key) { | |
$list[] = ['key' => $key, 'quality' => 1]; | |
} | |
array_walk($list, function (&$v, $k) { | |
// Decorate | |
$v['quality'] = [$v['quality'], $k]; | |
}); | |
usort($list, function ($a, $b) { | |
return strcmp($a['quality'], $b['quality']); | |
}); | |
array_walk($list, function (&$v, $k) { | |
// Undecorate | |
$v['quality'] = $v['quality'][0]; | |
}); | |
var_dump($list); |
This file contains 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
array(2) { | |
[0] => | |
array(2) { | |
'key' => | |
string(1) "x" | |
'quality' => | |
int(1) | |
} | |
[1] => | |
array(2) { | |
'key' => | |
string(1) "a" | |
'quality' => | |
int(1) | |
} | |
} |
This file contains 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
array(2) { | |
[0] => | |
array(2) { | |
'key' => | |
string(1) "a" | |
'quality' => | |
int(1) | |
} | |
[1] => | |
array(2) { | |
'key' => | |
string(1) "x" | |
'quality' => | |
int(1) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment