Home > Article > Backend Development > How to learn PHP implode()
Implode function understanding 1
implode() function combines array elements into a string.
1. How to understand the array elements;
2. Whether the array elements are the objects of action;
3. Whether the purpose of the action is to integrate them into a string;
implode function understanding 2
Syntax
implode(separator,array)
1. The implode parameter - whether the separator adds content to each key value of the array;
2. implode parameter 2: whether array is an array of objects to be used;
parameter
separator is optional. Specifies what is placed between array elements. Default is "" (empty string).
array required. Arrays to be combined into strings.
Explanation
Although the separator parameter is optional. However, for backward compatibility, it is recommended that you use two parameters.
1. Whether the separator parameter is optional;
2. Whether the implode parameter 2 arra is required;
Tips and comments
Comment: implode( ) can accept two parameter orders. However, due to historical reasons, explode() does not work. It must be ensured that the separator parameter comes before the string parameter.
implode function understanding 3
<?php $arr = array('H','I','J','K!'); echo implode('m ',$arr); ?>
The output result is: Hm Im Jm K!
<?php $arr = array('H','I','J','K!'); echo implode(' ',$arr); ?>
The output result is: H I J K!