Advertisement
NozdrachevNN

Task 25

Jun 4th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.51 KB | None | 0 0
  1. <?php
  2. $s = ('Pig latin is cool');
  3. $arr = explode(" ", $s);
  4. $prefix = $arr;
  5. $postfix = $arr;
  6. $result = [];
  7. array_walk($prefix, function(&$x) {$x = ($x[0].'ay'); } );
  8. array_walk($postfix, function(&$x) {$x=substr($x, 1); } );
  9.     foreach($postfix as $key=>$value) {
  10.         $result[] = $value.$prefix [$key];
  11.     }  
  12. var_dump($result);
  13.  
  14. from Artur
  15. <?php
  16. $s = ('Pig latin is cool');
  17. $arr = explode(" ", $s);
  18.  
  19. foreach ($arr as &$item) {
  20.     $item = substr($item, 1) . $item[0] . 'ay';
  21. }
  22.  
  23. var_dump($arr);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement