ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

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

user-image
تم إضافة السؤال من قبل Adel Ezat Fawzy Ellozy , Webdeveloper. , Saudi Arabian Maritiem Sports Federation
تاريخ النشر: 2017/03/13
Parvez Ahmed
من قبل 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
من قبل 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.

 

BK Shah
من قبل BK Shah

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
من قبل 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
من قبل medhatmahmoud mahmoud , Web Designer , Connect Computer Service Co

explode()   use to convert string to array

implode()   use to convert array to string

المزيد من الأسئلة المماثلة