How to convert an array to a string with PHP

Josh Sherman
1 min read
Software Development PHP

Converting an array to a string is a pretty frequent task when programming. Whether you want to join some sentences into a paragraph or just smash the values into some sort of hash, you can do so very simply with PHP’s implode function.

Implode takes 1 to 2 arguments. In it’s simplest form, you can pass it your array and the values will be joined by an empty string. The other option is to pass in the “glue” as the first argument which is the string that will be used to stick the array elements together. The glue is followed by the array:

$array = [

echo implode($array) // ABCDEFGHIJ...

echo implode('::', $array); // ABCDEFG::HIJ...
Join the Conversation

Good stuff? Want more?

Weekly emails about technology, development, and sometimes sauerkraut.

100% Fresh, Grade A Content, Never Spam.

About Josh

Husband. Father. Pug dad. Musician. Founder of Holiday API, Head of Engineering and Emoji Specialist at Mailshake, and author of the best damn Lorem Ipsum Library for PHP.

Currently Reading

Parasie Eve

Previous Reads

Buy Me a Coffee Become a Sponsor

Related Articles