explode() php functions are used create an array elements based on split the strings, implode() function is used to combine array elements with a separate sting.
explode() – split string based on delimiter and creates array.
implode() – joins the array element
explode()
explode() function is used to seperate a string based on delimiter and store in array.
[code type=php]
<?php
$a=”a,b,c,d”;
$arr=explode(‘,’,$a);
echo $arr[0];
echo $arr[1];
echo $arr[2];
echo $arr[3];
?>
[/code]
OUTPUT:
a
b
c
d
implode()
[code type=php]
<?php
if(isset($_POST[‘submit’]))
{
$choice=$_POST[‘col’];
$choice1=implode(‘,’,$choice);
echo $choice1;
mysql_query(“insert into tb values(“”,”$choice1″);
}
?>
<form method=”post” action=””>
Select your favourite color:
Black:<input type=”checkbox” name=”col[]” value=”black”>
White:<input type=”checkbox” name=”col[]” value=”white”>
<input type=”submit” name=”submit”>
</form>
[/code]