<?php
/*
Инициализируем массивы. Да простит меня ОП за смену структуры.
*/
$unitsMale = [
1 => 'один' , 2 => 'два' , 3 => 'три' , 4 => 'четыре' , 5 => 'пять' ,
6 => 'шесть' , 7 => 'семь' , 8 => 'восемь' , 9 => 'девять' ,
] ;
$unitsFemale = [
1 => 'одна' , 2 => 'две' , 3 => 'три' , 4 => 'четыре' , 5 => 'пять' ,
6 => 'шесть' , 7 => 'семь' , 8 => 'восемь' , 9 => 'девять' ,
] ;
$from10To19 = [
0 => 'десять' , 1 => 'одиннадцать' , 2 => 'двенадцать' , 3 => 'тринадцать' ,
4 => 'четырнадцать' , 5 => 'пятнадцать' , 6 => 'шестнадцать' ,
7 => 'семнадцать' , 8 => 'восемнадцать' , 9 => 'девятнадцать'
] ;
$tens = [
2 => 'двадцать' , 3 => 'тридцать' , 4 => 'сорок' , 5 => 'пятьдесят' ,
6 => 'шестьдесят' , 7 => 'семьдесят' , 8 => 'восемьдесят' , 9 => 'девяносто'
] ;
$hunds = [
1 => 'сто' , 2 => 'двести' , 3 => 'триста' , 4 => 'четыреста' ,
5 => 'пятьсот' , 6 => 'шестьсот' , 7 => 'семьсот' ,
8 => 'восемьсот' , 9 => 'девятьсот' ,
] ;
$rubleArr = [
0 => "рублей." , 1 => "рубль." , 2 => "рубля."
] ;
$thouArr = [
0 => "тысяч" , 1 => "тысяча" , 2 => "тысячи"
] ;
$millArr = [
0 => "миллионов" , 1 => "миллион" , 2 => "миллиона"
] ;
/*
Возвращаем нужное склонение НЕчислового составляющего.
*/
function inclineNotNum( $num , $mill , $thou , $ruble ) {
global $rubleArr , $thouArr , $millArr ;
if ( $num == 000 ) return "" ;
if ( $thou == 1 ) $valueArr = $thouArr ;
if ( $mill == 1 ) $valueArr = $millArr ;
if ( $ruble == 1 ) $valueArr = $rubleArr ;
$num % 100 >= 11 && $num % 100 <= 19 ? $outValue = " {$valueArr[0]} " : (
$num % 10 == 1 ? $outValue = " {$valueArr[1]} " : (
$num % 10 >= 2 && $num % 10 <= 4 ? $outValue = " {$valueArr[2]} " :
$outValue = " {$valueArr[0]} "
)
) ;
return $outValue ;
}
/*
Пишем прописью порядки чисел, идущие в input, ня.
*/
function numInWords( $num , $sexism ) {
global $unitsMale , $unitsFemale , $from10To19 , $tens , $hunds ;
// При помощи одноразового цикла декларируем функцию, которая возвращает
// склонения слов.
static $i = 0 ;
while ( $i < 1 ) {
function getWord( $numCell1 , $numCell2 , $extArr , $intArr ) {
global $unitsMale , $unitsFemale , $from10To19 , $tens , $hunds ;
$word = "" ;
$word = $intArr [ $numCell1 ] = $extArr [ $intArr [ $numCell2 ] ] ;
return $word ;
}
$i ++;
}
// Складываем слова, как конструктор.
if ( count ( $oneNumArr ) == 3 ) { if ( $oneNumArr [ 1 ] == 1 ) {
$order = getWord( 0 , 0 , $hunds , $oneNumArr ) . " " .
getWord( 1 , 2 , $from10To19 , $oneNumArr ) ;
} else {
$sexism ? $order = getWord( 0 , 0 , $hunds , $oneNumArr ) . " " .
getWord( 1 , 1 , $tens , $oneNumArr ) . " " .
getWord( 2 , 2 , $unitsFemale , $oneNumArr ) :
$order = getWord( 0 , 0 , $hunds , $oneNumArr ) . " " .
getWord( 1 , 1 , $tens , $oneNumArr ) . " " .
getWord( 2 , 2 , $unitsMale , $oneNumArr ) ;
}
} elseif ( count ( $oneNumArr ) == 2 ) { if ( $oneNumArr [ 0 ] == 1 ) {
$order = getWord( 0 , 1 , $from10To19 , $oneNumArr ) ;
} else {
$order = getWord( 0 , 0 , $tens , $oneNumArr ) . " " .
getWord( 1 , 1 , $unitsMale , $oneNumArr ) ;
}
} elseif ( count ( $oneNumArr ) == 1 ) { $order = getWord( 1 , 1 , $unitsMale , $oneNumArr ) ;
}
return $order ;
}
/*
Чиним детектор порядков чисел, и пропускаем их через функции выше.
*/
function detectOrdersAndGetOutput( $num ) {
$finaleNum = "" ;
if ( $num == 0 ) {
return "ноль рублей" ;
}
// Детектор строчкой ниже. Возможно, велосипед, но ничего лучше не придумал.
$millOrder = numInWords( $threeNumArr [ 0 ] , 0 ) . inclineNotNum( $threeNumArr [ 0 ] , 1 , 0 , 0 ) ;
$thouOrder = numInWords( $threeNumArr [ 1 ] , 1 ) . inclineNotNum( $threeNumArr [ 1 ] , 0 , 1 , 0 ) ;
$hundOrder = numInWords( $threeNumArr [ 2 ] , 0 ) . inclineNotNum( $threeNumArr [ 2 ] , 0 , 0 , 1 ) ;
count ( $threeNumArr ) == 3 ?
$finaleNum = $millOrder . $thouOrder . $hundOrder : ( count ( $threeNumArr ) == 2 ?
$finaleNum = $thouOrder . $hundOrder : $finaleNum = $hundOrder
) ;
return $finaleNum ;
}
$text1 = detectOrdersAndGetOutput( $amount1 ) ;
echo "На вашем счету {$text1} \n " ;
$text2 = detectOrdersAndGetOutput( $amount2 ) ;
echo "На вашем счету {$text2} \n " ;
$text3 = detectOrdersAndGetOutput( $amount3 ) ;
echo "На вашем счету {$text3} \n " ;
$text4 = detectOrdersAndGetOutput( $amount4 ) ;
echo "На вашем счету {$text4} \n " ;
PD9waHAKCmVycm9yX3JlcG9ydGluZygtMSk7Cm1iX2ludGVybmFsX2VuY29kaW5nKCd1dGYtOCcpOwoKLyoKCdCY0L3QuNGG0LjQsNC70LjQt9C40YDRg9C10Lwg0LzQsNGB0YHQuNCy0YsuINCU0LAg0L/RgNC+0YHRgtC40YIg0LzQtdC90Y8g0J7QnyDQt9CwINGB0LzQtdC90YMg0YHRgtGA0YPQutGC0YPRgNGLLgoqLwokdW5pdHNNYWxlID0gWwogICAgMSA9PiAn0L7QtNC40L0nLCAyID0+ICfQtNCy0LAnLCAzID0+ICfRgtGA0LgnLCA0ID0+ICfRh9C10YLRi9GA0LUnLCA1ID0+ICfQv9GP0YLRjCcsCiAgICA2ID0+ICfRiNC10YHRgtGMJywgNyA9PiAn0YHQtdC80YwnLCA4ID0+ICfQstC+0YHQtdC80YwnLCA5ID0+ICfQtNC10LLRj9GC0YwnLCAKXTsKJHVuaXRzRmVtYWxlID0gWwoJMSA9PiAn0L7Q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