WEB TUTORIALS
PRACTICE EXAMPLES
HTML REFERENCES
CSS REFERENCES
PHP REFERENCES

How to create a string by joining the values of an array in PHP

Topic: PHP / MySQLPrev|Next

Answer: Use the PHP implode() or join() function

You can use the PHP implode() or join() function for creating a string by joining the values or elements of an array with a glue string like comma (,) or hyphen (-).

Let's take a look at the following example to understand how it basically works:

<?php
$array = array("red", "green", "blue");
 
// Turning array into a string
$str = implode(", ", $array);
echo $str; // Outputs: red, green, blue
?>

Related FAQ

Here are some more FAQ related to this topic:

Bootstrap UI Design Templates Property Marvels - A Leading Real Estate Portal for Premium Properties