php join() function obtains a string composed of array elements. This article introduces to coders how to use the php join() function and basic examples. Interested coders can refer to it.
join() function returns a string composed of array elements.
join() function is an alias of implode() function.
Note: The join() function accepts two parameter orders. However, due to historical reasons, explode() does not work. You must ensure that the separator parameter comes before the string parameter.
Note: The separator parameter of the join() function is optional. However, for backward compatibility, it is recommended that you use two parameters.
<code class="language-php hljs">join(separator,<span class="hljs-keyword">array)</span></code>
参数 | 描述 |
---|---|
separator | 可选。规定数组元素之间放置的内容。默认是 ""(空字符串)。 |
array | 必需。要组合为字符串的数组。 |
返回值: | 返回由数组元素组合成的字符串。 |
PHP 版本: | 4 |
更新日志: | 在 PHP 4.3.0 中,separator 参数变成可选的。 |
Separate array elements with different characters:
<?php $arr = array('Hello','World!','I','love','Shanghai!'); echo join(" ",$arr)."<br>"; echo join("+",$arr)."<br>"; echo join("-",$arr)."<br>"; echo join("X",$arr); ?>
Run online