In this article, you will learn how to convert an array into the string using PHP’s built-in function
Convert an Array to String using PHP
The implode function takes two values as parameters.
implode ( string $glue , array $pieces ) : string
glue – It’s a value that is concatenated to each element of the array when output as a string. This can be skipped. But if there is nothing to “glue” the elements won’t have anything in between and appear adjacent.
array – It’s an array that you need to convert
<?php $arr = ["pizza", "cake", "fruit salad"]; echo "Menu:" . implode($arr); ?>
As you see the elements are glued together without any space between these.
<?php $arr = ["pizza", "cake", "fruit salad"]; $glue = " , "; echo "Menu: " . implode($glue, $arr); ?>