This'll save you a loop:
PHP Code:
//initial array
$array1 = array('bob');
$array2 = array('bob','martha');
$array3 = array('bob','martha','jim');
$count = count($array);
//implode will ignore the glue in single-element arrays,
//so we can run arrays 1 and 2 through the basic 'and' routine
if( $count < 3 )
{
$string = implode(' and ',$array);
}
else
{
//break array into comma-delimited string
$string = implode(', ',$array);
//get position of comma before the last array element
$spot = strrpos($string, ', ' . $array[$count - 1]);
//replace the ', ' before the last element with ' and '
$string = substr_replace($string, ' and ', $spot, 2);
}
//$array1 = 'bob'
//$array2 = 'bob and martha'
-- This message may have been cut off and the rest will only be shown to members. To become a member, click here --