1, 'name' => 'Laptop', 'price' => 1200, 'category' => 'Electronics'], ['id' => 2, 'name' => 'Mouse', 'price' => 25, 'category' => 'Electronics'], ['id' => 3, 'name' => 'Keyboard', 'price' => 75, 'category' => 'Electronics'], ['id' => 4, 'name' => 'Book', 'price' => 15, 'category' => 'Books'], ['id' => 5, 'name' => 'Monitor', 'price' => 300, 'category' => 'Electronics'], ]; // Sort by 'price' in ascending order using usort and the spaceship operator (<=>) usort($products, function($a, $b) { return $a['price'] <=> $b['price']; }); echo "Sorted by Price (Ascending): "; print_r($products); // Sort by 'name' in descending order usort($products, function($a, $b) { return $b['name'] <=> $a['name']; }); echo " Sorted by Name (Descending): "; print_r($products); // Sort by 'category' then by 'price' (multi-level sort) usort($products, function($a, $b) { $categoryComparison = $a['category'] <=> $b['category']; if ($categoryComparison === 0) { return $a['price'] <=> $b['price']; } return $categoryComparison; }); echo " Sorted by Category then Price: "; print_r($products);