In this tutorial we will learn How To Create a String By Joining Values of array in PHP. PHP implode() Function or join() Function can be used to join values of array to make one string.
Table of Contents
Using PHP implode() Function
PHP implode() Function returns a string from the elements of array.
PHP implode() Function takes elements from array, one by one and join them to convert it to a string.
Take a look at the code given below.
<?php
$array = array('How','To','Code','School');
$string = implode("",$array);
echo $string;
?>
The above code has four values which will be converted to one string 'HowToCodeSchool'.
To add space between values we can use the following code.
<?php
$array = array('How','To','Code','School');
$string = implode(" ",$array);
echo $string;
?>
Using PHP join() Function
PHP join() Function also returns the string from elements of the array.
PHP join() Function works exactly like implode() Function.
<?php
$array = array('How','To','Code','School');
$string = join(" ",$array);
echo $string;
?>