Skip to content

Instantly share code, notes, and snippets.

View danjohnson3141's full-sized avatar
🏠
Working from home

Dan Johnson danjohnson3141

🏠
Working from home
View GitHub Profile
@danjohnson3141
danjohnson3141 / prettyList()
Last active December 30, 2015 06:59
Like Ruby's to_sentance, this function returns a list separated by commas. Last item will be proceeded by "and". Example: prettyList(('a', 'b')) returns "a and b", prettyList(('a', 'b', 'c')) returns "a, b, and c". Alternate version with option array instead of individual params.
<?php
function prettyList($list)
{
$listCount = sizeOf($list);
if($listCount == 1) {
$listString = $list[0];
}
if($listCount == 2) {