bitandblack/sentence-construction

Creates nice sentences out of arrays

2.2.0 2025-04-14 06:21 UTC

This package is auto-updated.

Last update: 2025-04-14 06:21:37 UTC


README

PHP from Packagist Latest Stable Version Total Downloads License

Sentence construction

Creates nice sentences out of arrays.

Installation

This library is made for the use with Composer. Add it to your project by running $ composer require bitandblack/sentence-construction.

Usage

Create a sentence like that:

<?php

use BitAndBlack\SentenceConstruction;

$fruits = [
    'Apples', 
    'Bananas', 
    'Pears'
];

$sentence = new SentenceConstruction(
    glue: ', ', 
    glueLast: ' and ', 
    pieces: $fruits,
);

var_dump('I like ' . $sentence);

This will dump I like Apples, Bananas and Pears.

The SentenceConstruction class provides the method getSentence but is also stringable by itself, so you can simply echo it.

Help

If you have any questions, feel free to contact us under hello@bitandblack.com.

Further information about Bit&Black can be found under www.bitandblack.com.