PHP Implode
The PHP implode function is simply the opposite of the PHP explode function.
The PHP implode function will take bits and pieces of code and compact (implode) them all into one string.
There are two arguments to the implode function:
1. The code that needs to be imploded (the array)
2. The string used to join the code together
Imagine you have an ice tray that formed ice cubes and you decided you wanted crushed ice instead, so you took an ice cube out and smashed it to pieces. Later, you decide you really wanted a cube of ice, so you put all the little pieces of ice back in the tray to refreeze, later taking its original shape.
The pieces of ice represent the “array”. They are the bits and pieces of code that need to be imploded.
The ice tray represents the string used to join the code together.
PHP Implode Example
Let’s create an example of a simple implode function in action:
$tagline = implode(” “, $words);
for($i = 0; $i < count($words); $i++){
echo “Word #$i = $words[$i] <br />”;
}
echo “The JWRmedia.com tagline is: $tagline”;
This bit of code would display:
Word #0 = Where
Word #1 = Fortunes
Word #2 = Are
Word #3 = Made
The JWRmedia.com tagline is: Where Fortunes Are Made
The implode function took the entire “$words” array and converted it into one string!
Pretty amazing, huh? Too bad everything couldn’t be put back together as easily!




