oranfry/english-lists

There is no license information available for the latest version (1.0.0) of this package.

1.0.0 2024-11-15 02:42 UTC

This package is auto-updated.

Last update: 2024-12-15 03:25:38 UTC


README

This library enables you to render a PHP array as an English-language list.

For example, the array ['A', 'B', 'C', 'D'] becomes string 'A, B, C, and D'.

You can designate an alternative to the "and" (such as "or").

You can also turn off the oxford comma.

Installation

composer require oranfry/english-lists

Usage

use EnglishLists\EnglishLists;

$myArray = ['Blood', 'Toil', 'Tears', 'Sweat'];

echo EnglishLists::render(
    $myArray, // the array to render
    'or', // the final separator (default: and)
    false, // don't use an oxford comma (default: use oxford comma)
); // Blood, Toil, Tears or Sweat

echo EnglishLists::render(['One']); // One
echo EnglishLists::render(['One', 'Two']); // One and Two
echo EnglishLists::render(['One', 'Two', 'Three']); // One, Two, and Three