[ create a new paste ] login | about

Link: http://codepad.org/v1WBdlAe    [ raw code | output | fork ]

PHP, pasted on Oct 18:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
function cmp($a, $b)
{
    if ($stock[$a] != $stock[$b]) return $stock[$b] - $stock[$a];
    return strcmp($a, $b);
}

$a = array(5 => 'apple', 1 => 'banana', 6 => 'orange', 2 => 'kiwi');

uksort($a, "cmp");

foreach ($a as $key => $value) {
    echo "$key: $value\n";
}
?>


Output:
1
2
3
4
1: banana
2: kiwi
5: apple
6: orange


Create a new paste based on this one


Comments: