Skip to content

Instantly share code, notes, and snippets.

@tskrynnyk
Last active November 4, 2017 23:48
Show Gist options
  • Save tskrynnyk/3903d08e8d8dc133fa2aed6e19efec23 to your computer and use it in GitHub Desktop.
Save tskrynnyk/3903d08e8d8dc133fa2aed6e19efec23 to your computer and use it in GitHub Desktop.
In words
<?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