PHP Array to string

Basically, the conversion from a PHP Array to a string can be easily done by the implode() function. So, here you will find some examples.

Output:

So, the variable $string has now the contents of the PHP Array. The implode() function usage is: implode(separator,array);

For example, some more ways on how you can convert a PHP array to string:

More info on the implode() function can be found here.

Multidimensional PHP Array to String

Maybe in case you need to convert a multidimensional array into a string, you may want to use the print_r() function. By adding “true” as its second parameter, all the contents of the array will be cast into the string.

Example:

Then, the output:

More info on the PHP function print_r() can be found here.

Leave a Reply

Your email address will not be published. Required fields are marked *