PHP implode() function
The PHP implode() functions converts array to string using given separator. By using implode() function you can join all the array elements and form a string. implode() function works as same as the join() function in PHP. The implode function is binary safe and you can pass the array elements in any order.
Basic Syntax
string implode(separator,array)
Name | Description |
---|---|
separator | This is optional parameter used to place between two array elements. The default value is “”. |
array | array of elements to convert to string. |
Return Value
The php implode function returns the string formed using array elements.
Examples
Following are the examples of implode() method.
1. Separating array elements by spaces using implode() function
<?php $arr = array('Apple','Banana','Cat','Dog','Elephant'); echo implode(" ",$arr)."<br>"; ?>
The output should be:
Apple Banana Cat Dog Elephant
2. Separating array elements by comma using implode() function
<?php $arr = array('White','Blue','Red','Orange','Voilet','Black'); echo implode(",",$arr)."<br>"; ?>
The output should be:
White,Blue,Red,Orange,Voilet,Black
LATEST POSTS
-
numpy.reshape() in Python
-
numpy.ones() in Python
-
Python string strip() method
-
C++ do-while loop with Example
-
numpy.argmin() in Python
-
Queue C++
-
Java Convert Integer to String
-
numpy.where() in Python with Examples
-
C strcmp() function with example
-
fscanf() in C with Examples
-
length and length() in Java
-
numpy.dot() in Python