implode

本文详细介绍了PHP中的implode函数,该函数用于将数组元素连接成一个字符串。文章提供了使用示例,并解释了如何设置粘合字符串以及如何处理空数组的情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

implode

(PHP 4, PHP 5)

implode — Join array elements with a string

说明

string implode ( string $glue , array $pieces )
string implode ( array $pieces )

Join array elements with a glue string.

Note:

implode() can, for historical reasons, accept its parameters in either order. For consistency with explode() , however, it may be less confusing to use the documented order of arguments.

 

参数

 

glue

Defaults to an empty string.

pieces

The array of strings to implode.

 

返回值

Returns a string containing a string representation of all the array elements in the same order, with the glue string between each element.

更新日志

版本说明
4.3.0The glue parameter became optional.

 

范例

 

Example #1 implode() example

<?php

$array  = array( 'lastname' ,  'email' ,  'phone' );
$comma_separated  =  implode ( "," ,  $array );

echo  $comma_separated ;  // lastname,email,phone

// Empty string when using an empty array:
var_dump ( implode ( 'hello' , array()));  // string(0) ""

?>

 

 

注释

Note: 此函数可安全用于二进制对象。

参见

 

转载于:https://www.cnblogs.com/haidong/p/4370921.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值