Hello Friends Today, through this tutorial, I will tell you How do you convert an array to a string using PHP With Example? In PHP, you can convert an array to a string using the `implode()` function, which joins array elements with a string separator. Here’s an example:
<?php $array = array("apple", "banana", "orange"); $string = implode(", ", $array); echo $string; ?>
Output:
apple, banana, orange
In this example, the `implode()` function joins the elements of the `$array` with “, ” (comma followed by a space) as the separator, creating a string where array elements are concatenated with the separator.
Alternatively, you can use the `join()` function, which is an alias for `implode()`:
<?php $array = array("apple", "banana", "orange"); $string = join(", ", $array); echo $string; ?>
Output:
apple, banana, orange
Both `implode()` and `join()` serve the same purpose of converting an array to a string in PHP.