How to create a comma-separated list from an array in PHP?

Spread the love

Sometimes, we want to create a comma-separated list from an array in PHP.

In this article, we’ll look at how to create a comma-separated list from an array in PHP.

How to create a comma-separated list from an array in PHP?

To create a comma-separated list from an array in PHP, we can use the implode function.

For instance, we write

$arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
$string = implode(",", $arr);

to call implode with ',' and $arr to combined the entries in $arr into a string with each entry separated by commas.

Conclusion

To create a comma-separated list from an array in PHP, we can use the implode function.

Leave a Reply

Your email address will not be published.