I want to add a comma to every item except the last one. The last one must have \"and\".
Item 1, Item 2 and Item 3
But items can be from 1 +
So if on
Well if it is an array just use implode(...)
implode(...)
Example:
$items = array("Item 1", "Item 2", "Item 3", "Item 4"); $items[count($items) - 1] = "and " . $items[count($items) - 1]; $items_string = implode(", ", $items); echo $items_string;
Demo: http://codepad.viper-7.com/k7xISG