Joining Array Values into a Single String in PHP

Q

How To Join Multiple Strings Stored in an Array into a Single String in PHP?

✍: FYIcenter.com

A

If you multiple strings stored in an array, you can join them together into a single string with a given delimiter by using the implode() function. Here is a PHP script on how to use implode():

<?php 
$date = array('01', '01', '2006');
$keys = array('php', 'string', 'function');
print("A formated date: ".implode("/",$date)."\n");
print("A keyword list: ".implode(", ",$keys)."\n");
?>

This script will print:

A formated date: 01/01/2006
A keyword list: php, string, function

 

PHP Built-in Functions for Arrays

⇒⇒PHP Tutorials

2017-01-05, 285👍, 0💬