Press "Enter" to skip to content

What is explode and implode in PHP?

0

Sometimes we need to convert an array into a string with some separator parameter, and also convert a set of comma-separated string into an array, to make this possible PHP has two functions:-

  1. Explode Function
  2. Implode Function

Explode Function:– The explode function split the string in to array. It will break the string in to smaller pieces by providing parameters in its method.

This function accept first parameter as separator and second one is string.

Example:-

<?php
    $string = "a,b,c,d,e";
    $exp_array = explode(",", $string);
    print_r($exp_array);
?>

Implode Function:– The implode function is used to convert array in to string, it return the array in a form of string.

This except the parameter first as separator and second is an array. This function is binary-safe.

Example:-

<?php
    $array = array("a,b,c,d,e");
    $string = implode(",", $array);
    echo $string;
?>
How to count number of variable parameter in a function - PHP
How to send Emails using Sendgrid in PHP?