PHP | Implode and Explode Function

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

ParameterDescription
separatorIt’s optional parameters. By default set empty.
arrayRequired. 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

ParameterDescription
separatorIt’s is delimeter and required.
stringString, which you want to break
limitOptional. 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)

AuthorTuts Make

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Javascript, JQuery, Laravel, Codeigniter, Vue JS, Angular JS, React Js, WordPress and Bootstrap from a starting stage.

Leave a Reply

Your email address will not be published. Required fields are marked *