PHP | Implode and Explode Function
Php 13-Sep-2021

PHP | Implode and Explode Function

In this PHP post, we would like to share with you, two PHP functions. Which are implode() and explode().

You can use both functions with PHP arrays and strings. And here also take examples like an array to string conversion in PHP, the string to array conversion in PHP.

PHP implode() Function

Implode function is a built-in function of php, which is used to convert array to string by provided delimiter.

Syntax

implode(separator,array)

Parameters of implode function

Parameter Description
separator It’s optional parameters. By default set empty.
array Required. The array to join to a string

Example:- array to string conversion in php

<?php 
$array = array('1','2','3','4','5');
echo implode(" ", $array);

Output

1,2,3,4,5

PHP Explode

Explode function is a built-in function of php, which is used to convert/break string to an array by a provided delimiter.

Syntax

explode(separator,string,limit)

Parameters of explode function

Parameter Description
separator It’s is delimeter and required.
string String, which you want to break
limit Optional. Specifies the number of array elements to return.

Example:- string to array conversion in php

<?php
$string = "1,2,3,4,5";
print_r(explode(",", $string));

Output

Array ([0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5)