How to use join in PHP
In this article I will explain how the join() function can be used in PHP.
join() function in PHP
- The join() function returns a string from the elements of an array.
- The join() function is an alias of the implode() function.
- The join() function accept its parameters in either order.
- The separator parameter of join() is optional.
Syntax
Parameter
- separator separator is required parameter. separator puts between the array elements, the default value is an empty string.
- array array is optional parameter. array to join into string.
Example
The following example show to how the join() function can be used in PHP.
<html>
<body>
<h3 style="color: blueviolet;">join() function example in PHP</h3>
<?php
$array=array('1','2','3','4','....');
echo"Apply join function with ',' <br/>";
$join_string=join(",", $array);
echo $join_string;
echo '<br>';
echo"Apply join function with '-' <br/>";
$array=array('A','B','C','D','E');
$join_string=join("-", $array);
echo $join_string;
?>
</body>
</html>
|
Output
You may also want to read these related articles here
Ask Your Question
Got a programming related question? You may want to post your question here