Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.37 KB | None | 0 0
  1. <?php
  2. $input = explode(', ', readline());
  3. $towns = [];
  4. for ($i = 0, $j = 1; $i < count($input) - 1; $i += 2,$j += 2){
  5.     $town = $input[$i];
  6.     $income = $input[$j];
  7.     if (array_key_exists($town, $towns)){
  8.         $towns[$town] += $income;
  9.     }else{
  10.         $towns[$town] = $income;
  11.     }
  12. }
  13. foreach ($towns as $key => $value){
  14.     echo "$key => $value".PHP_EOL;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement