Implode and Explode function of Php
<?php
// function 1: implode()
echo "<h1>IMPLODE</h1>";
$arr=array("test1","test2","test3","test4","test5","test6","test7","test7");
echo "<pre>"; print_r($arr); echo "</pre>";
//implode(glue, pieces)
echo "Array with glue=none";
echo "</br>";echo "</br>";
$str=implode('', $arr);
echo $str;
echo "</br>";echo "</br>";
echo "Array with ',' as glue to get comma separarted value from array ";
echo "</br>";echo "</br>";
$str=implode(',', $arr);
echo $str;
echo "</br>";echo "</br>";
// implode() function is used to join array elements and return string
// function 2: explode(delimiter, string)
echo "<h1>EXPLODE</h1>";
echo $str="This is my string i am going to explode";
echo "</br>";echo "</br>";
echo "First using space as delimiter";
echo "<pre>"; print_r($arr); echo "</pre>";
$arr=explode(' ',$str);
echo "</br>";echo "</br>";
echo "Now using t as delimiter";
$arr=explode('t',$str);
echo "<pre>"; print_r($arr); echo "</pre>";
// explode breaks string into array where delimiter comes
?>
<?php
// function 1: implode()
echo "<h1>IMPLODE</h1>";
$arr=array("test1","test2","test3","test4","test5","test6","test7","test7");
echo "<pre>"; print_r($arr); echo "</pre>";
//implode(glue, pieces)
echo "Array with glue=none";
echo "</br>";echo "</br>";
$str=implode('', $arr);
echo $str;
echo "</br>";echo "</br>";
echo "Array with ',' as glue to get comma separarted value from array ";
echo "</br>";echo "</br>";
$str=implode(',', $arr);
echo $str;
echo "</br>";echo "</br>";
// implode() function is used to join array elements and return string
// function 2: explode(delimiter, string)
echo "<h1>EXPLODE</h1>";
echo $str="This is my string i am going to explode";
echo "</br>";echo "</br>";
echo "First using space as delimiter";
echo "<pre>"; print_r($arr); echo "</pre>";
$arr=explode(' ',$str);
echo "</br>";echo "</br>";
echo "Now using t as delimiter";
$arr=explode('t',$str);
echo "<pre>"; print_r($arr); echo "</pre>";
// explode breaks string into array where delimiter comes
?>
No comments:
Post a Comment