Store all array values into a single variable as CSV in PHP
I have an array containing numbers 1-5 (sometimes more). All the members in the array can be displayed using the php function foreach
. But, how can I display all the members of my array by storing it in a single开发者_StackOverflow variable as csv (like1, 2, 3, 4, 5
), and thereby printing that variable only?
You could use the function implode()
.
For example
$csv_var = implode(', ', $array);
Have a look at the Manual.
精彩评论