In this tutorial, you shall learn how to convert an array into a string in PHP using implode() function, with example programs.

PHP Convert Array to String

To convert an array to string in PHP, use implode() String function. implode(separator, array) returns a string with the elements or array joined using specified separator.

Examples

1 Convert integer array to string

In the following example, we take an array of numbers, and convert the array to string, using , as separator between the elements of array.

PHP Program

<?php
$arr = array(5, 2, 9, 1);
$output = implode(", ", $arr);
printf("Output String : %s", $output);
?>

Output

2 Convert string array to string

In the following example, we take an array of strings, and convert the array to string, using , as separator between the elements of array.

PHP Program

<?php
$arr = array("apple", "banana", "cherry");
$output = implode(", ", $arr);
printf("Output String : %s", $output);
?>

Output

Conclusion

In this PHP Tutorial, we learned how to convert an array into a string, using implode(), with examples.