Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $inventory = array(
- array("type"=>"fruit", "price"=>3.50),
- array("type"=>"milk", "price"=>2.90),
- array("type"=>"pork", "price"=>5.43),
- );
- $price = array();
- foreach ($inventory as $key => $row)
- {
- $price[$key] = $row['price'];
- }
- echo 'Before Sort';
- echo '<pre>';print_r($inventory);echo '</pre>';
- echo 'Price array()';
- echo '<pre>';print_r($price);echo '</pre>';
- array_multisort($price, SORT_DESC, $inventory);
- echo '<pre>';print_r($inventory);echo '</pre>';
- // result
- Before Sort
- Array
- (
- [0] => Array
- (
- [type] => fruit
- [price] => 3.5
- )
- [1] => Array
- (
- [type] => milk
- [price] => 2.9
- )
- [2] => Array
- (
- [type] => pork
- [price] => 5.43
- )
- )
- Price array()
- Array
- (
- [0] => 3.5
- [1] => 2.9
- [2] => 5.43
- )
- Array
- (
- [0] => Array
- (
- [type] => pork
- [price] => 5.43
- )
- [1] => Array
- (
- [type] => fruit
- [price] => 3.5
- )
- [2] => Array
- (
- [type] => milk
- [price] => 2.9
- )
- )
Advertisement
Add Comment
Please, Sign In to add comment