Hongmu Notes
Home Language Notes PHP implode() function
Language Notes PHP

PHP implode() function

PHP implode() function

The function is to combine array elements into strings:


<?php
$arr = array('Hello','World!','I','love','Shanghai!');
echo implode(" ",$arr);
?>

Definition and usage

The implode() function returns a string composed of array elements.

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.

Note: This function is binary safe.

Grammar


implode(separator,array)
parameters Description
separator Optional. Specifies what is placed between array elements. Default is "" (empty string).
array Required. Arrays to be combined into strings.

More examples

Separate array elements with different characters:


<?php
$arr = array('Hello','World!','I','love','Shanghai!');
echo implode(" ",$arr)."<br>";
echo implode("+",$arr)."<br>";
echo implode("-",$arr)."<br>";
echo implode("X",$arr);
?>
微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

PHP ob function record

PHP ob function record Language Notes PHP

Usage of the following three functions ob_get_contents(); ob_end_clean(); ob_start(); You can use these functions to buffer local files and execute local script code. Use ob_start() to save the output code into the buffer, and the page will not be displayed; then use ob_get_contents to get the data in the buffer. o…
👁 141
PHP preg

PHP preg Language Notes PHP

The preg_match_all function is used to perform a global regular expression match. preg_match_all() Syntax int preg_match_all ( string $pattern , string $subject [, array &$matches [, int $flags = PREG…
👁 169
Detailed explanation of PHP ternary operator and if

Detailed explanation of PHP ternary operator and if Language Notes PHP

Ternary operator condition ? Result 1 : Result 2 Explanation: The position in front of the question mark is the condition for judgment. If the condition is met, the result is 1, and if it is not met, the result is 2. This article compares and explains the ternary operator and if...else... in detail. I hope it will be helpful to everyone. Today when I was revising my paper online, I encountered a statement that I couldn’t understand: $if_summary = $row['IF_SUMMARY']=…
👁 189
PHP cast type

PHP cast type Language Notes PHP PHP collection PHP and mysql

Get the data type 1. If you want to check the value and type of an expression, use var_dump(). 2. If you just want to get an easy-to-read type expression for debugging, use gettype(). 3. To check a certain type, do not use gettype(), but use the is_type() function. Converting Strings to Numbers When a string is evaluated as a number, the result is determined according to the following rules...
👁 232

Recommended reading

Summary of commonly used Bootstrap 5 form `pattern` attribute

Summary of commonly used Bootstrap 5 form `pattern` attribute Language Notes Bootstrap

Summary of commonly used Bootstrap 5 form `pattern` attribute: **Text input field validation**: Validates whether the value entered into a text input field matches a specified regular expression. For example, `pattern= "[a-zA-Z]{3,}$" ` ensures that the string contains at least 3 letters, and the last character cannot be a digit or a space. **Password input field validation**: Validates whether the value entered into a password input field matches a specified regular expression. For example,...
👁 339
(PC+WAP) Exhibition Website Template – Download Exhibition Website Source Code: 0947

(PC+WAP) Exhibition Website Template – Download Exhibition Website Source Code: 0947 Practical Collection pbootcms Template

A PbootCMS website template designed for trade shows, compatible with both PC and WAP devices. Its sophisticated and professional design makes it ideal for exhibition organizers to showcase event schedules, booth reservations, and service offerings. This template helps exhibition companies attract exhibitors and visitors online. Template Preview | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn | Related Articles: PbootCMS...
👁 53
Responsive tea set sales website template 1192

Responsive tea set sales website template 1192 Practical Collection Yiyou template

This EyouCMS responsive template is ideal for the tea and tea ware sales industry. Its classical and elegant design is perfect for showcasing tea products, tea ceremony culture, brand stories, and sales information. It helps tea brands effectively present their products online and attract tea enthusiasts. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS...
👁 35
(Adaptive mobile version) Automotive driving school website template – Driving license training website source code download: 0948

(Adaptive mobile version) Automotive driving school website template – Driving license training website source code download: 0948 Practical Collection pbootcms Template

A PbootCMS website template designed for automotive driving schools and driver's license training programs, compatible with both PC and WAP devices. Its professional and practical design is ideal for driving schools to showcase their courses, instructors, and enrollment information. This template helps driving schools attract students online and boost their student conversion rates. Template Preview | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn | Related Articles: PbootC...
👁 54
Responsive tea beverage sales website template – 1193

Responsive tea beverage sales website template – 1193 Practical Collection Yiyou template

An EyouCMS responsive website template designed for the tea and tea beverage sales industry. Its fresh and elegant design is ideal for showcasing tea products, brand stories, tea culture, and sales information. This template helps tea beverage brands effectively present their products online and attract consumers. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS...
👁 58