Syntax of implode() function and Usage
implode(separator,array)
Parameter Values
separator -> This is an optional parameter .Specifies what to put between the array elements. if not provided the default is “”
(i.e. an empty string).
array -> Required.The array whose value is to be joined to form a string.
Let's learn
1.Create array.
$arr = array('Hello','World!','Welcome','to','BAJARANGISOFT.');
2.Print array elements using implode() function.
echo implode(" ",$arr);
Example(1)
<?php
$arr = array('Hello','World!','Welcome','to','BAJARANGISOFT.');
echo implode(",",$arr);// with separator
echo implode(" ",$arr);//without separator
?>
Complete Code of implode() Function:
<!DOCTYPE html>
<html lang="en">
<head>
<title>PHP implode function</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="text-center">
<h1>PHP implode() Function</h1>
</div>
<br>
<h2>The implode() function join the elements of an array</h2>
<div class="well">
<?php
$arr = array('Hello','World!','Welcome','to','BAJARANGISOFT.');
echo "<h4>".implode(",",$arr)."</h4>";//with separator
echo "<h4>".implode(" ",$arr)."</h4>";//without separator
?>
</div>
<br>
</div>
</body>
</html>