Home  >  Article  >  Backend Development  >  How to use php join

How to use php join

angryTom
angryTomOriginal
2019-08-23 16:11:243535browse

How to use php join

PHP join() function

Combines array elements into a string:

<?php
    $arr = array(&#39;Hello&#39;,&#39;World!&#39;,&#39;I&#39;,&#39;love&#39;,&#39;Shanghai!&#39;);
    echo join(" ",$arr);
?>

Definition and usage

 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.

Syntax

join(separator,array)
Parameters Description
separator Optional. Specifies what is placed between array elements. Default is "" (empty string).
array Required. Arrays to be combined into strings.

Technical details

##Return value: Returns a string composed of array elements. PHP Version: 4 Change Log: In PHP 4.3.0,
separator Parameter becomes optional.

More examples

Separate array elements with different characters:


<?php
    $arr = array(&#39;Hello&#39;,&#39;World!&#39;,&#39;I&#39;,&#39;love&#39;,&#39;Shanghai!&#39;);
    echo join(" ",$arr)."<br>";
    echo join("+",$arr)."<br>";
    echo join("-",$arr)."<br>";
    echo join("X",$arr);
?>

The above is the detailed content of How to use php join. For more information, please follow other related articles on the PHP Chinese website!

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