What is the function of PHP implode ()?
The implode () function in PHP returns a string composed of array elements that, contrary to the PHP explode () function, is the PHP explode () function that splits another string with one string and returns an array of strings.
Understanding the function of the PHP implode () function, let's take a look at the syntax of the PHP implode () function and its example.
Grammar
1 |
implode(separator, array ) |
Detailed parameters:
Parameters |
Description |
Separator |
Optional. Specifies what is placed between the elements of the array. The default is "" (an empty string). |
Array |
Necessary. An array to combine as a string. |
Note: the implode () function accepts two parameter orders. However, for historical reasons, explode () is not possible, and you must ensure that the separator parameter precedes the string parameter.
Note: The separator parameter of the implode () function is optional. However, for backwards compatibility, it is recommended that you use two parameters.
Example
To separate the array elements with different characters, the code is as follows:
12345678910 |
<?php
$arr
=
array
(
‘Hello‘
,
‘World!‘
,
‘Beautiful‘
,
‘Day!‘
);
echo
implode(
" "
,
$arr
).
"<br>"
;
echo
implode(
"+"
,
$arr
).
"<br>"
;
echo
implode(
"-"
,
$arr
).
"<br>"
;
echo
implode(
"X"
,
$arr
);
?>
|
Code Run Result:
"Related articles recommended"
1. PHP explode () function instance detailed
2. How to use the PHP explode () function
PHP implode () function