Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

What are the uses of PHP functions ( implode and explode ) ?

user-image
Question ajoutée par Adel Ezat Fawzy Ellozy , Webdeveloper. , Saudi Arabian Maritiem Sports Federation
Date de publication: 2017/03/13
Parvez Ahmed
par Parvez Ahmed , Frontend Developer (Angular) , GREEN DELTA INSURANCE COMPANY LIMITED

Implode() Function

The implode function is used to "join elements of an array with a string".

The implode() function returns a string from elements of an array. It takes an array of strings and joins them together into one string using a delimiter (string to be used between the pieces) of your choice. 

<?php$arr = array ('I','am','simple','boy!');$space_separated = implode(" ", $arr);$comma_separated = implode(" , ", $arr);$slash_separated = implode(" / ", $arr);?>

Explode() Function

 

The explode function is used to "Split a string by a specified string into pieces i.e. it breaks a string into an array".

<?php$str="I am simple boy!";print_r(explode(" ",$str));?>

 

alaa liswe
par alaa liswe , ِAdministrative Assistant , Arab Open University

The implode() function returns a string from the elements of an array.

Explode() Function

The explode function is used to "Split a string by a specified string into pieces i.e. it breaks a string into an array".

The explode function in PHP allows us to break a string into smaller text with each break occurring at the same symbol. This symbol is known as the delimiter. Using the explodecommand we will create an array from a string. The explode() function breaks a string into an array, but the implode function returns a string from the elements of an array.

 

The different is following,

Implode()

  • Returns a string containing a string representation of all the array elements in the same order, with the glue string between each element.
  • string implode ( string $glue , array $pieces )
  •  $array = array('lastname', 'email', 'phone');$comma_separated = implode(",", $array);echo $comma_separated; // lastname,email,phone

explode()

  • Returns an array of strings, each of which is a substring of string formed by splitting it on boundaries formed by the string delimiter.
  • array explode ( string $delimiter , string $string [, int $limit = PHP_INT_MAX ] )
  • $pizza  = "piece1 piece2 piece3 piece4 piece5 piece6";$pieces = explode(" ", $pizza);echo $pieces[0]; // piece1echo $pieces[1]; // piece2

Hope It will  help.

 

Kamal Hasija
par Kamal Hasija , Web Developer , The Brihaspati Infotech Pvt. Ltd.

As I think in simple terms that

implode function will generates special characters into a string. like (spaces, @, !, coma etc.).

explode did the opposite it will break or remove the special characters from string.

 

and in technical ways,

explode function will break down a string into more parts that will be manageable!

implode function will use to concatenate them and joined break parts to a single string again.

 

that's it!

 

Regards,

 

Kamal

 

medhatmahmoud mahmoud
par medhatmahmoud mahmoud , Web Designer , Connect Computer Service Co

explode()   use to convert string to array

implode()   use to convert array to string

More Questions Like This

Avez-vous besoin d'aide pour créer un CV ayant les mots-clés recherchés par les employeurs?