PHP join() Function
Instance
Combine array elements into a string:
<?php $arr = array('Hello','World!','I','love','Shanghai!'); echo join(" ",$arr); ?>
Definition and Usage
join() function returns a string composed of array elements.
join() function is implode() function alias.
Note:join() function accepts two parameter orders. However, due to historical reasons, explode() is not available, you must ensure that separator The parameter is in string before the parameter.
Note:join() Function's separator The parameter is optional. However, for backward compatibility, it is recommended that you use two parameters.
Syntax
join(separator,array)
Parameter | Description |
---|---|
separator | Optional. Specifies the content placed between array elements. The default is "" (empty string). |
array | Required. The array to be combined into a string. |
Technical Details
Return Value: | Returns a string composed of array elements. |
PHP Version: | 4+ |
Update Log: | In PHP 4.3.0,separator Parameters become optional. |
More Examples
Example 1
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); ?>