yii\helpers\BaseInflector::sentence PHP Метод

sentence() публичный статический Метод

Special treatment is done for the last few words. For example, php $words = ['Spain', 'France']; echo Inflector::sentence($words); output: Spain and France $words = ['Spain', 'France', 'Italy']; echo Inflector::sentence($words); output: Spain, France and Italy $words = ['Spain', 'France', 'Italy']; echo Inflector::sentence($words, ' & '); output: Spain, France & Italy
С версии: 2.0.1
public static sentence ( array $words, string $twoWordsConnector = ' and ', string $lastWordConnector = null, string $connector = ', ' ) : string
$words array the words to be converted into an string
$twoWordsConnector string the string connecting words when there are only two
$lastWordConnector string the string connecting the last two words. If this is null, it will take the value of `$twoWordsConnector`.
$connector string the string connecting words other than those connected by $lastWordConnector and $twoWordsConnector
Результат string the generated sentence
    public static function sentence(array $words, $twoWordsConnector = ' and ', $lastWordConnector = null, $connector = ', ')
    {
        if ($lastWordConnector === null) {
            $lastWordConnector = $twoWordsConnector;
        }
        switch (count($words)) {
            case 0:
                return '';
            case 1:
                return reset($words);
            case 2:
                return implode($twoWordsConnector, $words);
            default:
                return implode($connector, array_slice($words, 0, -1)) . $lastWordConnector . end($words);
        }
    }