PHP join () function
Examples
The elements of an array to a string:
<?php
$arr = array('Hello','World!','Beautiful','Day!');
echo join(" ",$arr);
?>
$arr = array('Hello','World!','Beautiful','Day!');
echo join(" ",$arr);
?>
Running instance »
Definition and Usage
join () function returns a combination of array elements into a string.
join () function is the implode () alias function.
NOTE: join () function accepts two arguments in order.However, due to historical reasons, the explode () is not enough, you must ensure that the separator argument before the string parameter down.
NOTE: join () separator function parameters are optional.However, for backward compatibility, it is recommended that you use two parameters.
grammar
join( separator,array )
参数 | 描述 |
---|---|
separator | 可选。规定数组元素之间放置的内容。默认是 ""(空字符串)。 |
array | 必需。要组合为字符串的数组。 |
technical details
return value: | It returns a combination of array elements into a string. |
---|---|
PHP version: | 4+ |
Update log: | Since PHP 4.3.0, separator parameters become optional. |
More examples
Example 1
An array of characters separated by different elements:
<?php
$arr = array('Hello','World!','Beautiful','Day!');
echo join(" ",$arr)."<br>";
echo join("+",$arr)."<br>";
echo join("-",$arr)."<br>";
echo join("X",$arr);
?>
$arr = array('Hello','World!','Beautiful','Day!');
echo join(" ",$arr)."<br>";
echo join("+",$arr)."<br>";
echo join("-",$arr)."<br>";
echo join("X",$arr);
?>
Running instance »
PHP String Reference