EXPLODE
function explode() is used to split a string into pieces. Cutting of the string depending upon a substring or a single character, and returns the chunked form of the string as an array.
For example you have a string
$text="Ali,Jeff,Joel,Cortex,Charly";
now you want to make each name as element of array and access it individually
so what you do:
$arr = explode(",", $text);
means : we have made pieces of string $text based on seperator ',' and put the resulting array in variable $arr
so now $arr contains data as shown following, By the way the following result can be generated by using print_r() fucntion, which prints out the actual structure of data cotnained in a variable.
So I used print_r($arr); and results are following
Array( [0] => Ali [1] => Jeff [2] => Joel [3] => Cortex [4] => Charly )
which is equal to
$arr = Array("Ali","Jeff","Joel","Cortex","Charly");
IMPLODE
function implode() is oppisite to the explode function. It rejoins any array elements and returns the resulting string, which may be put in a variable.
Take the same example we had above
Your have an array $arr = Array("Ali","Jeff","Joel","Cortex","Charly");
and you wish to combine it in a string, by putting a seperator '/' between each element of the array.
how to do that?
answer: $str = implode("/",$arr);
so your resulting string varialbe $str will be containg Ali/Jeff/Joel/Cortex/Charly
which may be presented in php code as $str="Ali/Jeff/Joel/Cortex/Charly";
I hope it helps please reply back, if you need more help on it.
|
|
|