what are Implode and Explode functions?
Answers were Sorted based on User's Feedback
Answer / -=pkg=-
The implode() function takes an already existing array as
it's argument, and concatenates the contents of
each element in the array into a string.
where as explode() function performs reverse to implode()
function. It splits the string into items by a
delimiter, such as a dash, ampersand, space and places each
item into a new array.
| Is This Answer Correct ? | 52 Yes | 8 No |
Answer / puneet bhatt
explode function:-it breaks a string into array.
<?php
$str="hello world.it's a beautiful day.":
print_r(explode(" ",$str):
?>
ans-ARRAY
[0]=>hello
[1]=>world.
[2]=>it's
[3]=>a
[4]=>beautiful
[5]=>day.
implode:-returns a string from elements of an array.
<?php
$arr=array('hello','world!',beautiful,'day!');
echo implode(" ",$arr);
?>
ans-hello world! beautiful day!
| Is This Answer Correct ? | 36 Yes | 5 No |
Answer / inno dev
explode= convert string into an array
such as
$pizza = "piece1 piece2 piece3 piece4 piece5 piece6";
$pieces = explode(" ", $pizza);
echo $pieces[0];
echo $pieces[1];
echo $pieces[2];
echo $pieces[3];
echo $pieces[4];
echo $pieces[5];
Implode=Join array elements with a string
means convert array into a string
such as
<?php
$array = array('lastname', 'email', 'phone');
$comma_separated = implode(",", $array);
echo $comma_separated;
?>
| Is This Answer Correct ? | 22 Yes | 2 No |
Answer / suraj raut paul
Implode()
this just concatenate the variables and placed into one single variable for example
<form action=<?php $_php_self; ?> method="post">
<label for="dob">Enter Your date of Birth</label>
<select name="day">Day</option>
<option value="1">sun</option>
<option value="2">mon</option>
</select>
<select value="month">Month
<option value="1">Jan</option>
<option value="2">feb</option>
</select>
<select name="year">year
<option value="2012">2012</option>
<option value="2011">2011</option>
</select>
when sending this value in database in single field then you need to join all the values in single variable that is
$dob= implode(array($_post['day'], $_post['month', $_post['year']));
Then it's just concatenated all these values come from the from into single variable $dob.
Explode()
this is the function that is just reverse of the implode.
that it's just split the value given in one varible into array.
| Is This Answer Correct ? | 9 Yes | 0 No |
Answer / jhon
Implode and Explode are function sthat are opposite in working
Explode converts a string into array where as implode
coverts an array in string
explode example
<?php
$str = "test explode in php";
print_r (explode(" ",$str));
?>
output will be:
Array
(
[0] => test
[1] => explode
[2] => in
[3] => php
)
implode example
<?php
$arr = array('hi','hello');
echo implode(" ",$arr);
?>
output will be:
hi hello
| Is This Answer Correct ? | 6 Yes | 1 No |
Answer / kalaimani.k mca (gurunanak col
Example . explode()
<?php
$history= "php4 php5 php6";
$pieces = explode(" ", $history);
//separated the arrays
echo $history[0]; // php3
echo $history[1]; // php4
echo $history[1]; // php5
?>
//implode Join array elements with a string
implode() example
<?php
$array = array('lastname', 'email', 'phone');
$comma_separated = implode(",", $array);
echo $comma_separated;
//lastname,email,phone
| Is This Answer Correct ? | 4 Yes | 1 No |
Answer / jaimin
Explode function is use to convert string into an array and
Implode function is use to convert an array into string.
| Is This Answer Correct ? | 2 Yes | 2 No |
Answer / ajay dabhi
Explode function converts comma separated string value into
array
Implode function converts array into comma separated string
| Is This Answer Correct ? | 22 Yes | 24 No |
What is the role of the .htaccess file in php?
Tell us how can we display the output directly to the browser?
What are the different filter functions used to filter a variable?
How to calculate the difference between two dates using php?
What is php in full?
Does php 7 support multiple inheritance?
Can you use php and javascript together?
What should we do to be able to export data into an excel file?
How do I clear my browser session?
difference between clanguage and c++
Write a program to swap two numbers using php.
What is php? Why it is used?