uasort();
PHP Code:
<?php
$d = array(
"set1"=>array(
"name"=>"Product 1",
"price"=>"22.00"),
"set2"=>array(
"name"=>"Product 2",
"price"=>"12.00"),
"set3"=>array(
"name"=>"Product 3",
"price"=>"244.00")
);
// sort low to high
uasort ( $d, create_function ( '$a,$b', 'return ( $a["price"] == $b["price"] ? 0 : ( $a["price"] < $b["price"] ? -1 : 1 ) );' ) );
print_r ( $d );
// sort high to low
uasort ( $d, create_function ( '$a,$b', 'return ( $a["price"] == $b["price"] ? 0 : ( $a["price"] > $b["price"] ? -1 : 1 ) );' ) );
print_r ( $d );
?>
Bookmarks