In this tutorial, you shall learn how to convert an array of strings to a CSV string in PHP using join() function, with the help of example programs.

PHP – Convert Array of strings to CSV string

To convert an array of strings to CSV string in PHP, use join() function. Call join() function and pass the separator string "," and the array of strings as arguments.

Example

In this example, we take a string array in $arr and join them with comma as separator.

PHP Program

<?php
$arr = ["apple", "banana", "cherry"];
$output = join(",", $arr);
echo $output;
?>

Output

PHP - Convert Array of strings to CSV string

Conclusion

In this PHP Tutorial, we learned how to convert an array of strings to CSV string, using join() function.