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.

matthom is published and produced by Matt Thommes - an independent publishing enthusiast, mobile blogger, content creator, informative writer, web developer from a suburb of 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

Popular Pages

  1. Fast rounded corners in Photoshop (7873 recent visits)
  2. PHP – passing variables across pages (2857 recent visits)
  3. JavaScript set selected on load (2345 recent visits)
  4. Removing all child nodes from an element (1704 recent visits)
  5. iPod songs out of order? (1412 recent visits)
  6. Firefox 3 smart address bar: wildcard search (1300 recent visits)
  7. Britney - Everytime piano tab (1180 recent visits)
  8. MySQL LEFT JOIN syntax (971 recent visits)
  9. Breathe Me - Sia (824 recent visits)
  10. Tumblr: how blogging should be (727 recent visits)

Similar Entries

Stats

110 unique visits since August 2008

Syndicate

Advertisements