Implode and explode in PHP with example


Implode and explode in PHP

Implode and explode in PHP are the two built-in functions of PHP. These are widely used in web applications. Sometimes, we want to insert a similar set of elements like selecting multiple dropdown values or inserting multiple checkbox values into the database in PHP.

With the help of implode functions, we can do this. In this tutorial, I will explain these two functions one by one.

Illustration of Implode and Explode in PHP

Implode function takes the input array elements one by one and holds the elements using a separator and returns a string by joining all the elements of the array with the separator.

Syntex:- implode(separator, array)

whereas

  • “separator” separates the resultant string.
  • and “array” is the input array that is taken as the multiple inputs.

Example:-
In this example, assume that we have a list of cars as an array that has to be shown or inserted in the database.

$cars = array(‘Maruti’, ‘Volvo’, ‘BMW’, ‘Marcedes’);

Now, if you want to echo the car’s array then you have to wrap the above array using the implode() function as shown below.

<?php

$cars = array('Maruti','Volvo','BMW','Marcedes');

echo implode(' , ', $cars).'<br>';
echo implode(' + ', $cars).'<br>';
echo implode(' and ', $cars).'<br>';
echo implode(' or ', $cars);

?>

Output:-

Maruti , Volvo , BMW , Marcedes
Maruti + Volvo + BMW + Marcedes
Maruti and Volvo and BMW and Marcedes
Maruti or Volvo or BMW or Marcedes

I have used four types of separators for the same array. You can use the separator as per your choice.

Explode function is opposite to the implode function. This function breaks a string and store all the string elements using a separator in an array and return the array one by one.

Syntex:- explode(separator, array)

Whereas

  • “separator” separates the string elements
  • “array” is the input string

Example:-
In this example, we will break the above cars array one by one with the help of for loop.

Note:- Try to use for loop while using the explode function

<?php

$cars = array('Maruti','Volvo','BMW','Marcedes');

for($i=0;$i<sizeof($cars);$i++)
{
   echo 'The name of the car is  '.$cars[$i].'<br>';
}

?>

Output:-

The name of the car is Maruti
The name of the car is Volvo
The name of the car is BMW
The name of the car is Marcedes

Conclusion:- I hope this tutorial will help you to understand the concept of implode and explode functions. If there is any doubt then please leave a comment below.


Leave a Comment

THOR311

ceri188

ceri188

ceri188

KUPU178

HOKI311

RATU311

KUPU178

RATU311

RATU311

kupu178

kupu178

HOKI311

togel

kupu178

ratu311

mix parlay

ceri188

slot online

kupu178

KUPU178

RATU311

THOR311

THOR311

KUPU178

KUPU178

KUPU178

RATU311

RATU311

RATU311

kupu178

hoki311

THOR311

hoki311

togel online

kupu178

slot mahjong

ceri188

slot server thailand

ratu311

ceri188

ceri188

RATU311

punjabi virasat

mimcord.com

Centrum Medyczne

www.vrcorporate.in

phbalance.vn

KUPU178

daftar slot gacor

hoki311

togel hongkong

kupu178

slot mahjong

ratu311

slot gacor

kupu178

kupu178

ceri188

kupu178

ceri188

KUPU178

KUPU178

KUPU178

RATU311

kupu178

RATU311

RATU311

RATU311

KUPU178

KUPU178

RATU311

RATU311

slot online

kupu178

thor311

thor311

kupu178

kupu178

RATU311

KUPU178

THOR311

THOR311

KUPU178

slot mahjong ways

hoki311

slot gacor

ceri188

ratu311

kupu178

Casino Baccarat Online

kupu178

kupu178

ceri188

ceri188

THOR311

RATU311

toto macau

KUPU178

slot gacor

HOKI311

sabung ayam online

RATU311

SLOT LUCKY NEKO

CERI188

Slot Gacor

KUPU178

RATU311

RATU311

Link Spaceman

CERI188

Slot Gacor Online

THOR311

Mahjong ways

KUPU178

THOR311

THOR311

Live Casino

HOKI311

CERI188

CERI188

THOR311

THOR311

THOR311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

KUPU178

KUPU178

CERI188

HOKI311 SLOT

TOTO TOGEL TOKYO

CERI188

CERI188 SITE

CERI188

RATU311

RATU311

RATU311

RATU311

RATU311

KUPU178

Toto Togel

KUPU178

Slot Mahjong

CERI188

CERI188

CERI188

Slot Sweet Bonanza 2500

KUPU178

SLOT ONLINE

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

KUPU178

KUPU178 X SLOT777

judi bola online

THOR311

KUPU178 10 GAME SLOT TERBAIK

KUPU178

KUPU178 SLOT TERPERCAYA

KUPU178 TOGEL

TOTO 4D MACAU

KUPU178

SITUS BOLA

CERI188

KUPU178

RATU311

THOR311

HOKI311

KUPU178

RATU311

THOR311

CERI188

Slot Mahjong Ways

KUPU178

CERI188

Slot Online Resmi

KUPU178

RATU311 SLOT ONLINE

KUPU178

KUPU178: Link Akses Resmi

KUPU178: Strategi Menang Di Game Live Casino

KUPU178

KUPU178: Minimal 200 Rupiah

Slot Gacor Online

KUPU178

Mix Parlay

CERI188

CERI188

THOR311

THOR311

THOR311

THOR311

THOR311

KUPU178

Slot Thailand

CERI188

CERI188

THOR311 RTP

RATU311

RATU311

RATU311

CERI188

KUPU178 TOTO SLOT

CERI188 TOTO Singapore

THOR311

KUPU178

KUPU178

RATU311

CERI188

RATU311: Alternatif karnpuracollege

RATU311

RATU311

Thor311 Terbaru

THOR311 MAHJONG

RATU311: BONUS SABUNG AYAM

CERI188: Masuk Akun Slot Super Cepat

THOR311 PRO

CERI188

CERI188

CERI188

THOR311

HOKI311

HOKI311

RATU311

HOKI311

KUPU178

RATU311

RATU311

RATU311

RATU311

THOR311

CERI188

CERI188

RATU311

RATU311

RATU311

RATU311

Game Thor311

HOKI311

HOKI311

RATU311

HOKI311

HOKI311

THOR311

RATU311 NONTON BOLA

RATU311

HOKI311 Link QRIS EWALLET

RATU311

HOKI311 Link Apk Resmi

CERI188

RATU311 judi bola

KUPU178

situs judi bola

HOKI311

RATU311

THOR311

HOKI311

KUPU178

kupu178 link alternatif

kupu178 slot

kupu178 daftar

kupu178 login

link daftar kupu178

judi bola

RATU311

link alternatif RATU311

Link daftar RATU311

link login RATU311

RATU311

KUPU178

KUPU178

RATU311

RATU311

KUPU178

THOR311

slot thailand

judi bola

KUPU178

slot gacor

slot gacor

yakuza303

slot gacor

RATU311

THOR311