Showing posts with label Difference between implode and explode in php. Show all posts
Showing posts with label Difference between implode and explode in php. Show all posts

Wednesday 3 May 2017

Difference between implode and explode in php

Implode() Function ex:
The implode function is used to "join elements of an array with a string".

The implode() function returns a string from elements of an array. It takes an array of strings and joins them together into one string.
which means "Array to String conversion".
syntax:
implode (separator , array);
example:
<?php
$array = ("s","h","a","n","a","v","a","s");
$ats = implode ("-",$array);
print $ats;
?>
result;
s-h-a-n-a-v-a-s
Explode() Function ex:
The explode function is used to "Split a string by a specified string into pieces i.e. it breaks a string into an array".
which means "String to Array conversion".
Syntax:explode (separator,string,limit)
<?php
$sta = "This is Shanavas";
print_r(explode(" ",$sta));
?>
result:
Array ([0]=> This [1]=>is [2]=>Shanavas)