Book HomePHP CookbookSearch this book

4.9. Turning an Array into a String

4.9.2. Solution

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 ","

4.9.4. See Also

Recipe 4.10 for printing an array with commas; documentation on join( ) at http://www.php.net/join and substr( ) at http://www.php.net/substr.



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.