implode() and explode() functions in PHP with Example Short Explanation


1. implode() function in PHP
-In the PHP implode() function is used to convert Array into String, implode() function returns the string from elements of the array in PHP.
-Basically, implode() function is just used for conversation purpose Array to String

Syntax:
string implode(seperator,array);
Example:

<?php
$site[0]="cwipedia.in";
$site[1]="circuitcoder.com";
$text=implode(",", $site);
echo "$text";
?>
Output:
           cwipedia.in,circuitcoder.com

2.explode() function in PHP
-In the PHP explode() function is used to break String into an array.
-or we can say explode() function is used to split a string into an array element.

Syntax:
aaray explode(Seperator,orignal_string,no_of_elements);
-explode() function access three parameters two are compulsory and one is optional
-the last one no_of_elements is optional

Example:
<?php
$site[0]="cwipedia.in";
$site[1]="circuitcoder.com";
$text=implode(",", $site);
print_r(explode(",",$text))
?>
Output:
Array ( [0] => cwipedia.in [1] => circuitcoder.com )

Comments