Jump to content


This topic is now archived and is closed to further replies.


implode and exsplode need more examples please

Recommended Posts

I am trying to get to grips with implode and exsplode but need more proper examples and exsplenations thank you..

Is all this string miniplnation?

example implode

I understand this the implode gets the string and then adds the and.
$result=implode(" and " , $num);
echo $result;

exsplode example
quit dont get to grips with this the explode gets the string the with
any space out puts the result with a for loop.

do you need always to use for loops on explode?
$sentence="my little cat";
$result=explode(" " , $sentence);
for($i=0; $i< count($result); $i++) {
echo " number is ".$i." and ".$result[$i]."<br>";

thank you for your support.

Share this post

Link to post
Share on other sites
Implode syntax:
string [b]implode[/b] ( string glue, array pieces )

the glue bit is the sting or range of characters that gets inserted between values within an array. which is the pieces part. So for example. If you have any array that stores names or words and yiu want an easy way of displaying this arrat you'll want to use implode. Now you want to display your name or words seperated by a coma. This is how you'll do it:

$num = array("one", "two", "three"," four");
$result = implode(", " , $num);
echo $result;

?>[/code]That will will result in this: [i]one, two, three, four[/i]

Explode syntax:
array [b]explode[/b] ( string separator, string string [, int limit] )

Explode is alittle diferent to implode as Explode custs up strings, depending on the seperator specified and puts each cut section into an array. So take this for example:
So you have string like so:
[i]hello I am redarrow[/i] and you want each word to be put into an array you'll soiemthing like this:

$string = "Hello I am redarrow";
$words = explode(" ", $string);

?>[/code]You'll now get an any like so:
[i]array("Hello", "I", "am", "redarrow")[/i]

You dont have to use a for loop no. As you can echo out each word sperately like so:
[code]echo $words[0];
echo $words[1];

Thats all there is to it. To get a better explanation always check the PHP manul for thse two functions
[a href=\"http://www.php.net/implode\" target=\"_blank\"]implode[/a]
[a href=\"http://www.php.net/explode\" target=\"_blank\"]explode[/a]

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.