Code mnemonics: PHP implode/explode Jun22 '05

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.

Categories: Efficiency , PHP

Add Feedback (view all)

Leave feedback

Feedback

Input format: The editor controls below will assist with Markdown syntax.

Status

Sub-status

Your info

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" function ... Read more.

The implode equivalent in javascript is called "join" ... Read more.

matthom is published and produced by Matt Thommes - an independent publishing enthusiast, mobile blogger, content creator, informative writer, web developer from Chicago. Never one to conform, Matt intends to promote the effect the web has on our lives, in an effort to intensify, instruct, and clarify all that is happening around us.

Contact Matt

Similar Entries

Stats

517 unique visits since August 2008

Syndicate

Advertisements