By Alvin Alexander. Last updated: June 4, 2016
PHP array to CSV FAQ: How do your convert a PHP array to a CSV string?
Converting a PHP array to a PHP CSV string is so easy, it actually felt like I trick question when I just found the answer in the PHP docs.
In my case, I just had a PHP array named $tags
, and I wanted to convert it to a PHP CSV string. To do this, all I had to do was use the PHP implode function, like this:
$csv_string = implode(',', $tags);
After issuing this command, the variable $csv_string
now contains all the elements from the array $tags
as a single CSV string (a string of comma-separated values).