Prado\I18N\core\ChoiceFormat::format PHP Method

format() public method

For the choice string, and a number, find and return the string that satisfied the set within the choices.
public format ( $string, $number ) : string
return string the choosen string.
    public function format($string, $number)
    {
        list($sets, $strings) = $this->parse($string);
        $total = count($sets);
        for ($i = 0; $i < $total; $i++) {
            if ($this->isValid($number, $sets[$i])) {
                return $strings[$i];
            }
        }
        return false;
    }

Usage Example

Example #1
0
 function test_english()
 {
     $choice = new ChoiceFormat();
     $string = '[0] none |{n: n % 10 == 1} 1st |{n: n % 10 == 2} 2nd |{n: n % 10 == 3} 3rd |{n:n} th';
     $wants = array('none' => array(0), '1st' => array(1, 11, 21), '2nd' => array(2, 12, 22), '3rd' => array(3, 13, 23), 'th' => array(4, 5, 6, 7, 14, 15));
     foreach ($wants as $want => $numbers) {
         foreach ($numbers as $n) {
             $this->assertEquals($want, $choice->format($string, $n));
         }
     }
 }
All Usage Examples Of Prado\I18N\core\ChoiceFormat::format