Last active
November 4, 2017 23:48
-
-
Save tskrynnyk/3903d08e8d8dc133fa2aed6e19efec23 to your computer and use it in GitHub Desktop.
In words
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class InWords | |
{ | |
private static $words = array(); | |
protected static $numbers = ['zero', 'jeden', 'dwa', 'trzy', 'cztery', 'pięć', 'sześć', 'siedem', 'osiem', 'dziewięć']; | |
protected static $operands = ['+' => 'plus', '-' => 'minus', '*' => 'razy']; | |
public static function get($str) | |
{ | |
$s = explode(' ', $str); | |
for($i = 0; $i < count($s); $i++) | |
{ | |
if (is_numeric($s[$i])) { | |
self::$words[] = self::$numbers[$s[$i]]; | |
} else { | |
self::$words[] = self::$operands[$s[$i]]; | |
} | |
} | |
return implode(' ', self::$words); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment