Implode and explode function in PHP; Through this tutorial, we will show you everything about implode() and explode() function in PHP.
We can use both functions with PHP arrays and strings. And here also take examples like an array to string conversion in PHP, the string to array conversion in PHP.
Implode and Explode in PHP
- PHP implode() Function
- PHP Explode Function
PHP implode() Function
Implode function is a built-in function of php, which is used to convert array to string by provided delimiter.
Syntax
implode(separator,array)
Parameters of implode function
Parameter | Description |
---|---|
separator | It’s optional parameters. By default set empty. |
array | Required. The array to join to a string |
Example:- array to string conversion in php
<?php
$array = array('1','2','3','4','5');
echo implode(" ", $array);
Output
1,2,3,4,5
PHP Explode Function
Explode function is a built-in function of php, which is used to convert/break string to an array by a provided delimiter.
Syntax
explode(separator,string,limit)
Parameters of explode function
Parameter | Description |
---|---|
separator | It’s is delimeter and required. |
string | String, which you want to break |
limit | Optional. Specifies the number of array elements to return. |
Example:- string to array conversion in php
<?php
$string = "1,2,3,4,5";
print_r(explode(",", $string));
Output
Array ([0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5)
Recommended PHP Tutorials
- Compare Arrays PHP | PHP array_diff() Function
- Get, Write, Read, Load, JSON File from Url PHP
- Functions: Remove First Character From String PHP
- Remove Specific/Special Characters From String In PHP
- How to Replace First and Last Character From String PHP
- Reverse String in PHP
- Array Push, POP PHP | PHP Array Tutorial
- PHP Search Multidimensional Array By key, value and return key
- json_encode()- Convert Array To JSON | Object To JSON PHP
- PHP remove duplicates from multidimensional array
- PHP Remove Duplicate Elements or Values from Array PHP
- Get Highest Value in Multidimensional Array PHP
- PHP Get Min or Minimum Value in Array
- String PHP to Uppercase, Lowercase & First Letter Uppercase
- PHP: isset() vs empty() vs is_null()
- Chunk_split PHP Function Example
- PHP Function: Date and Time With Examples
- Reverse Number in PHP | PHP Tutorial