search
HomeBackend DevelopmentPHP ProblemHow to convert array into string in php

php method to convert an array into a string: first create a PHP sample file; then define an array data as "$arr"; then use the "implode($arr);" method to convert the array into String; finally output the conversion result.

How to convert array into string in php

Recommended: "PHP Video Tutorial"

The operating environment of this tutorial: Windows 7 system, PHP version 5.6, This method works for all brands of computers.

PHP implode(): Array to string

implode() function can convert a one-dimensional array into a string. The syntax format is as follows:

implode($glue, $array) or implode($array)

Among them, $glue is used to set a string, indicating that $glue is used to connect each element of the array together. By default $glue is an empty string; $array is the array that needs to be converted.

Tip: The $glue parameter of the implode() function is optional and can be omitted.

[Example] Use the implode() function to convert an array into a string.

<?php
    $arr = [&#39;PHP中文网&#39;,&#39;PHP教程&#39;,&#39;http://www.php.cn/php/&#39;,&#39;implode()函数&#39;,&#39;数组转字符串&#39;];
    $str = implode($arr);
    echo $str.&#39;<br>&#39;;
    $str = implode(&#39; &#39;,$arr);
    echo $str.&#39;<br>&#39;;
    $str = implode(&#39;,&#39;,$arr);
    echo $str.&#39;<br>&#39;;
    $str = implode(&#39;--&#39;,$arr);
    echo $str.&#39;<br>&#39;;
?>

The running results are as follows:

PHP中文网PHP教程http://www.php.cn/php/implode()函数数组转字符串
PHP中文网 PHP教程 http://www.php.cn/php/ implode()函数 数组转字符串
PHP中文网,PHP教程,http://www.php.cn/php/,implode()函数,数组转字符串
PHP中文网--PHP教程--http://www.php.cn/php/--implode()函数--数组转字符串

The above is the detailed content of How to convert array into string in php. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools