Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $input = explode(', ', readline());
- $towns = [];
- for ($i = 0, $j = 1; $i < count($input) - 1; $i += 2,$j += 2){
- $town = $input[$i];
- $income = $input[$j];
- if (array_key_exists($town, $towns)){
- $towns[$town] += $income;
- }else{
- $towns[$town] = $income;
- }
- }
- foreach ($towns as $key => $value){
- echo "$key => $value".PHP_EOL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement