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

How to learn PHP implode()

PHP中文网
Release: 2023-02-28 18:12:01
Original
1223 people have browsed it

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)
Copy after login

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); 
?>
Copy after login

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); 
?>
Copy after login

The output result is: H I J K!

Related labels:
Statement of this Website
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
Latest Articles by Author
Latest Issues
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template