Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- declare(strict_types=1);
- /**
- *
- * Pig Latin is a game of alterations played on the English language game.
- * To create the Pig Latin form of an English word the initial consonant sound is transposed to the end of the word
- * and an ay is affixed (Ex.: "banana" would yield anana-bay).
- * Read Wikipedia for more information on rules.
- *
- */
- function pigLatin(string $str){
- if(!ctype_alpha($str)){
- throw new InvalidArgumentException('в строке могут быть только буквы');
- }
- $str = strtolower($str);
- define('VOWELS', array('a','e', 'i', 'o', 'u', 'y'));
- $i = 0;
- while($i<=strlen($str)-1){
- if(!in_array($str[$i],VOWELS)){
- $str .= $str[$i];
- $str = substr($str, 1);
- }else{
- break;
- }
- }
- return $str . "ay";
- }
- var_dump(pigLatin('three'));
Add Comment
Please, Sign In to add comment