If I have an array that looks like this:
$str = '';
if( $_POST['first'] )
$str = $_POST['first'];
if( $_POST['second'] )
$str .= ($str != '' ? ',' : '') . $_POST['second'];
if( $_POST['third'] )
$str .= ($str != '' ? ',' : '') . $_POST['third'];
if( $_POST['fourth'] )
$str .= ($str != '' ? ',' : '') . $_POST['second'];
$str .= ($str != '' ? '.' : '');
Which gives me something like this:
Joe, Adam, Mike.
However, I would like to add an "and" before the last item.
So it would then read:
Joe, Adam, and Mike.
How can I modify my code to do this?