How to convert array into string in php

藏色散人
Release: 2023-03-07 21:58:01
Original
1971 people have browsed it

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.

'; $str = implode(' ',$arr); echo $str.'
'; $str = implode(',',$arr); echo $str.'
'; $str = implode('--',$arr); echo $str.'
'; ?>
Copy after login

The running results are as follows:

PHP中文网PHP教程//m.sbmmt.com/php/implode()函数数组转字符串 PHP中文网 PHP教程 //m.sbmmt.com/php/ implode()函数 数组转字符串 PHP中文网,PHP教程,//m.sbmmt.com/php/,implode()函数,数组转字符串 PHP中文网--PHP教程--//m.sbmmt.com/php/--implode()函数--数组转字符串
Copy after login

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!

Related labels:
php
source:php.cn
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 Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!