what is difference between explode and implode functions?

April 11, 2010 | Filed Under PHP | Comments Off

explode — Split a string by string

explode, split a string and return an array by using niddle in the string.

Example . explode()

<?php
// Example 1
$
history= "php4 php5 php6";
$pieces = (" ", $
history);
echo
$
history[0]; // php3
echo $history[1]; // php4

echo $history[1]; // php5
?>

implode — Join array elements with a string

Example: implode() example

<?php
$array
= array('lastname', 'email', 'phone');
$comma_separated = implode(",", $array);
echo
$comma_separated; // lastname,email,phone
?>

Comments

Comments are closed.

© PHPInterviewQuestion.com 2009 - 2012

eXTReMe Tracker