PHP implode() Function
In this chapter you will learn:
- Definition for PHP implode() Function
- Syntax for PHP implode() Function
- Parameter for PHP implode() Function
- Example - Convert array to string
Definition
The implode()
function converts an array into a string by inserting a separator
between each element.
This is the reverse of the explode()
function.
Syntax
PHP implode() Function has the following syntax.
string implode ( string separator, array pieces )
Parameter
Parameter | Meaning |
---|---|
separator | Separator to use to connect the array elements |
pieces | Array to implode |
Example 1
Convert array to string
<?PHP//j a va 2 s. co m
$my = "A and B and C";
$my_array = explode(" and ", $my);
print_r($my_array);
print "\n";
$exclams = implode("! ", $my_array);
print_r($exclams);
print "\n";
$fruitArray = array( "apple", "pear", "banana", "strawberry", "peach" );
$fruitString = implode( ",", $fruitArray );
echo $fruitString;
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP in_array() Function
- Syntax for PHP in_array() Function
- Parameter for PHP in_array() Function
- Example - Is an element in an array
- Example - Use strict checking
Home » PHP Tutorial » PHP Array Functions