helpers\BaseInflector sentence()

sentence() public static method (available since version 2.0.1)

Converts a list of words into a sentence.

Special treatment is done for the last few words. For example,

$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
public static string sentence ( array $words, $twoWordsConnector = ' and ', $lastWordConnector = null, $connector = ', ' )
$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

return string

The generated sentence

doc_Yii
2016-10-30 17:05:24
Comments
Leave a Comment

Please login to continue.