Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $shops = [];
- $input = readline();
- while ("END" !== $input) {
- //Add->PeakSports->Map,Navigation,Compass
- // ->OneItem
- $args = explode("->", $input);
- $command = $args[0];
- $shopName = $args[1];
- if ($command === "Add") {
- $items = $args[2];
- $items = explode(",", $items);
- if (count($items) > 1) {
- foreach ($items as $item) {
- $shops[$shopName][] = $item;
- }
- } else {
- $shops[$shopName][] = $args[2];
- }
- } else {
- //Remove->Groceries
- unset($shops[$shopName]);
- }
- $input = readline();
- }
- uksort($shops, function ($shop1, $shop2) use ($shops) {
- $coun1 = count($shops[$shop1]);
- $coun2 = count($shops[$shop2]);
- if ($coun1 === $coun2) {
- return $shop2 <=> $shop1;
- }
- return $coun2 <=> $coun1;
- });
- echo "Stores list:" . PHP_EOL;
- foreach ($shops as $name => $products) {
- echo $name . PHP_EOL;
- foreach ($products as $product) {
- echo "<<$product>>" . PHP_EOL;
- }
- }
Add Comment
Please, Sign In to add comment