Turning an Array into a String

convert it into a  formatted string.
Use join( ):
// make a comma delimited list
$string = join(',', $array);

Or loop yourself:
$string = '';

foreach ($array as $key => $value) {
    $string .= ",$value";
}

$string = substr($string, 1); // remove leading ","
 
 
If you can use join( ), do; it's faster than any PHP-based loop. However, join( ) isn't very flexible. First, it places a delimiter only between elements, not around them. To wrap elements inside HTML bold tags and separate them with commas, do this:
$left = '<b>'; $right = '</b>'; $html = $left . join("$right,$left", $html) . $right;
Second, join( ) doesn't allow you to discriminate against values. If you want to include a subset of entries, you need to loop yourself:
$string = ''; foreach ($fields as $key => $value) { // don't include password if ('password' != $key) { $string .= ",<b>$value</b>"; } } $string = substr($string, 1); // remove leading ","