implode and explode in PHP

 








PHP implode:

implode() is a useful feature in PHP. implode() use for join the array by using a seperator.

sudo code will be like this:   implode(seperator, array).

See the example below:

<?php
$day = array('A','Beautiful','Rainy','Day!');
echo implode(" ",$day);
?>

The output will be : A Beautiful Rainy Day!

You can also set different sperator, See other example below:

<?php
$day = array('A','Beautiful','Rainy','Day!');
echo implode(" ",$day)."<br>";
echo implode("+",$day)."<br>";
echo implode("-",$day)."<br>";
?>

The output will be : A Beautiful Rainy Day!

                                  A+Beautiful+Rainy+Day!

                                  A-Beautiful-Rainy-Day!


PHP explode:

explode() is a useful feature in PHP. explode() use for breaks a string into an array.

See the example below:

<?php
$day = "A Beautiful Rainy Day!";

print_r (explode(" ",$day));

?>

The output will be : Array ( [0] => A [1] => Beautiful [2] => Rainy [3] => Day! )

Post a Comment (0)
Previous Post Next Post