Advertisement
NozdrachevNN

Task 33

Sep 6th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.41 KB | None | 0 0
  1. function orderWeight($str){
  2. $arr = explode(' ', $str);
  3. sort($arr);
  4. foreach ($arr as $value) {
  5.             $summ = 0;
  6.             for ($i=0; $i<strlen($value); $i++) {
  7.             $summ += $value[$i];
  8.             }
  9.     $arrKey[] = $summ;
  10. }
  11. $result = array_map (null, $arrKey, $arr);
  12. asort ($result);
  13. $result = array_map(function($a){ return  $a[1]; },$result);
  14. $s = implode(' ', $result);
  15. return ($s);
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement