Home Backend Development PHP Tutorial Detailed explanation of php implode() function example

Detailed explanation of php implode() function example

May 23, 2017 pm 02:53 PM

What is the function of php implode() function?

The implode() function in php returns a string composed of array elements. It has the opposite effect to the php explode() function. php explode() The function is: split a string using another string and return an array of strings.

Understanding the role of the php implode() function, let’s take a look at the syntax and examples of the php implode() function

Grammar

implode(separator,array)
Copy after login

Parameter details:

##ParameterDescriptionOptional. Specifies what is placed between array elements. Default is "" (empty string). Required. Arrays to be combined into strings.
separator
array

Note: The implode() function accepts two parameter orders. However, due to historical reasons, explode() does not work. You must ensure that the separator parameter comes before the string parameter.

Note: The separator parameter of the implode() function is optional. However, for backward compatibility, it is recommended that you use two parameters.

Example

Use different characters to separate array elements, the code is as follows:

<?php
$arr = array(&#39;Hello&#39;,&#39;World!&#39;,&#39;Beautiful&#39;,&#39;Day!&#39;);
echo implode(" ",$arr)."<br>";

echo implode("+",$arr)."<br>";

echo implode("-",$arr)."<br>";

echo implode("X",$arr);
?>
Copy after login
Code running result:

Detailed explanation of php implode() function example

【Recommended related articles】

1.

php explode() function example detailed explanation

2.

Use of php explode() function method

The above is the detailed content of Detailed explanation of php implode() function example. For more information, please follow other related articles on the PHP Chinese website!

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Convert array to string using implode() function in PHP Convert array to string using implode() function in PHP Jun 26, 2023 pm 11:51 PM

Convert array to string using implode() function in PHP

How to use PHP explode function and solve errors How to use PHP explode function and solve errors Mar 10, 2024 am 09:18 AM

How to use PHP explode function and solve errors

PHP Warning: implode(): Invalid arguments passed solution PHP Warning: implode(): Invalid arguments passed solution Jun 23, 2023 am 09:04 AM

PHP Warning: implode(): Invalid arguments passed solution

Split and merge strings using the explode and implode functions Split and merge strings using the explode and implode functions Jun 15, 2023 pm 08:42 PM

Split and merge strings using the explode and implode functions

Common errors and solutions when using the explode function in PHP Common errors and solutions when using the explode function in PHP Mar 11, 2024 am 08:33 AM

Common errors and solutions when using the explode function in PHP

How to use implode function to concatenate array elements into string in PHP How to use implode function to concatenate array elements into string in PHP Jun 26, 2023 pm 02:02 PM

How to use implode function to concatenate array elements into string in PHP

Introduction to the usage of PHP implode() function Introduction to the usage of PHP implode() function Jun 27, 2023 am 10:56 AM

Introduction to the usage of PHP implode() function

Split string into array using PHP function 'explode' Split string into array using PHP function 'explode' Jul 24, 2023 pm 11:09 PM

Split string into array using PHP function 'explode'

See all articles