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.
In this example, we take a string array in
$arr and join them with comma as separator.
<?php $arr = ["apple", "banana", "cherry"]; $output = join(",", $arr); echo $output; ?>
In this PHP Tutorial, we learned how to convert an array of strings to CSV string, using