4Jean 4Jean - 6 months ago 10
PHP Question

What is the difference between implode and explode

Please what is the meaning of implode and explode functions in php
I did not understand how it was explained in these questions explode and implode - Codeigniter and explode and implode

Answer

The explode() function breaks a string into an array.

<?php
$str = "Hello world. It's a beautiful day.";
print_r (explode(" ",$str));
?>

Return: Array ( [0] => Hello [1] => world. [2] => It's [3] => a [4] => beautiful [5] => day. )

The implode() function returns a string from the elements of an array.

<?php
$arr = array('Hello','World!','Beautiful','Day!');
echo implode(" ",$arr);
?>

Return: Hello World! Beautiful Day!

Comments