Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this 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
?>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP  and MySQL Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to split a string into an array in PHP... >>
<< How to get current page URL in PHP...