PHP implode()的用法和explode()类似,但是功能却恰恰相反,implode()是将数组元素组合成一个字符串。
<?php $arr=array('a','b','c','d','e'); $s=implode($arr); //默认是以空字符合并数组元素 //$s=implode(',',$arr); //指定以","合并数组元素 echo $s; ?>
上面这是一个简单的一维数组,那么多维数组行不行呢?
<?php $arr=array('a','b',array('4','5','6'),'c','d','e',array('1','2','3')); //定义一个二维数组 $s=implode(',',$arr); echo $s; ?>
得到的结果是:
a,b,Array,c,d,e,Array
很显然,对于多维数组,implode()函数就无能为力了!那么多维数组怎样转字符串呢?如果先将多维数组转成一维数组,再通过implode()函数合并成字符串,不就可以完成了吗!关于多维数组转一维数组可以参考这篇文章PHP多维数组转一维数组的简单实现方法
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
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article
What's New in Windows 11 KB5054979 & How to Fix Update Issues
3 weeks agoByDDD
How to fix KB5055523 fails to install in Windows 11?
2 weeks agoByDDD
InZoi: How To Apply To School And University
4 weeks agoByDDD
How to fix KB5055518 fails to install in Windows 10?
2 weeks agoByDDD
Roblox: Dead Rails – How To Summon And Defeat Nikola Tesla
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Atom editor mac version download
The most popular open source editor

WebStorm Mac version
Useful JavaScript development tools
