Home  >  Article  >  Backend Development  >  How to learn PHP implode()

How to learn PHP implode()

PHP中文网
PHP中文网Original
2017-06-02 11:05:401169browse

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(&#39;H&#39;,&#39;I&#39;,&#39;J&#39;,&#39;K!&#39;); 
echo implode(&#39;m &#39;,$arr); 
?>

The output result is: Hm Im Jm K!

<?php
$arr = array(&#39;H&#39;,&#39;I&#39;,&#39;J&#39;,&#39;K!&#39;); 
echo implode(&#39;  &#39;,$arr); 
?>

The output result is: H I J K!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn