PHP中的implode()函数
该implode()函数用于通过字符串连接数组元素。
语法
implode(separator, arr)
参数
分隔符-指定要在数组元素之间包含的内容。默认值为“”
arr-要连接到字符串的数组
返回
该implode()函数从数组的元素返回一个字符串。
示例
以下是一个例子-
<?php
$arr = array('This','is','Demo','Text!');
echo implode("$",$arr);
?>输出结果
以下是输出-
This$is$Demo$text!
示例
以下是一个例子-
<?php
$myarr = array('This','is','Demo','Text!');
echo implode("-",$myarr);
echo implode("#",$myarr);
?>输出结果
以下是输出-
This-is-Demo-Text!This#is#Demo#Text!