Code mnemonics: PHP implode/explode

I’ve come up with some mnemonics for remembering the difference between the PHP functions, implode and explode, since I always confuse them, in my head.

First, their function

implode

implode acts on an array, and returns a
string:


$array = ("Oasis", "Coldplay", "Foo Fighters");

$string = implode(", ", $array);

echo $string;

The above code outputs:

Oasis, Coldplay, Foo Fighters

explode

explode acts on a string, and returns an array:


$string = "Oasis, Coldplay, Foo Fighters";

$array = explode(", ", $string);

echo $array[0];

The above code outputs:

Oasis

Mnemonics

Here’s a couple mnemonics relating to these PHP functions:

I Am String

Easy String i Am

The first line above (I Am String) translates to: Implode Array String (using the first letters). This further translates to: Implode acts on Array, and returns a String.

The second line above (Easy String i Am) translates to: Explode String Array (using the capital letters). This further translates to: Explode acts on String, and returns Array.

I Am Easily Separated

This contains both implode and explode mnemonics in the same line.

Just use the first letters: Implode Array Explode String.

Personally, I like the first mnemonic better. Even though it is two lines, as opposed to one, it is easier to remember, and even contains the word easy, which is similar to Microsoft employees only owning Dell digital music players, rather than iPods – a competitor.

2 thoughts on “Code mnemonics: PHP implode/explode

  1. I prefer “split” to “explode”, which is what Java and Javascript and some other languages use. Don’t think there’s any built-in “implode” functionality in Java or Javascript, though… just have to iterate over the array yourself or write a function to do that.

    To remember explode vs. implode, I think I’d just think about taking one string, exploding it into many little pieces (of an array).

Comments are closed.