Use Of Implode And Explode Function In PHP

LEVEL: Beginner

Whats in this post?

  1. Code
  2. Output
  3. Background and Explanation of the code

Code


To copy code: Click View Source “View Source” on the right of this code snippet.

Background and Explanation of the code

This post explains the two PHP functions implode and explode, that works on arrays. The implode function takes two arguments  – first is a separator and second is an array. A string is returned which consists of contents of the array with a separator in between them.
The explode function takes two arguments – first is a separator and second is a string. An array is returned which consists of contents of the string which are separated by the separator passed in as the first argument.

Output:

Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 [8] => 9 )
1/2/3/4/5/6/7/8/9

a,e,i,o,u
Array ( [0] => a [1] => e [2] => i [3] => o [4] => u )