Implode and Explode Function in PHP

Implode and Explode function of PHP is very useful to convert the array into string and string into an array for example when we collect data by using checkbox input then we receive data in an array format then we have two choices to get checkbox value either by using a loop or we can convert the array into a string by using implode function.

Implode() function

Implode() function is used to convert the array into a string, it uses any symbol to join an array. It is commonly used to convert checkbox values into strings to store easily in a database.




                 echo $price;
<!DOCTYPE html>
<html lang="en">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="[email protected]/dist/css/bootstrap.min.css">
  <script src="[email protected]/dist/jquery.slim.min.js"></script>
  <script src="[email protected]/dist/umd/popper.min.js"></script>
  <script src="[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<div class="container">
  <form method="post">
    <div class="form-group">
      <label for="email">Price:</label>
      <input type="checkbox" class="form-control" name="price[]">1000
 <input type="checkbox" class="form-control" name="price[]">2000
 <input type="checkbox" class="form-control" name="price[]">3000
<button type="submit" name="submit" class="btn btn-primary">Submit</button>  

In this example, implode is used to convert checkbox value into a string with the # symbol.

Explode() function

Explode() function is used to convert a string into an array or we can say that show implode() function value individually then we use explode.


explode(“symbol”,’ array’);


$number = '1,2,3,4,5';
$arr = explode(',',$number);
foreach($arr as $i)

Here explode function convert string into an array and we have used for each to show all elements of an array one by one.

Categories: web development php

Trending Courses


Regular : 45 Days

Fastrack : 20 Days

Crash : 10 Days

Advance Digital Marketing

Regular : 6 Months

Fastrack : 3 Months

Crash : 2 Months

React JS

Regular : 45 Days

Fastrack : 20 Days

Crash : 7 Days


Regular : 45 Days

Fastrack : 20 Days

Crash : 10 Days

Front End Developer

Regular : 7 Month

Fastrack : 4 Month

Crash : 2 Month

Related Blogs

Request For Demo