Current Location: Home> Function Categories> join

join

Alias ​​of implode
Name:join
Category:String
Programming Language:php
One-line Description:The alias for implode() .

Definition and usage

The join() function returns a string composed of array elements.

The join() function is an alias for implode() function.

Note: The join() function accepts two parameter orders. However, due to historical reasons, explode() is not possible. You must ensure that the separator parameter is 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.

Example

Example 1

Combine array elements into a string:

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

Try it yourself

Example 2

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 ) ;
?>

Try it yourself

grammar

 join ( separator , array )
parameter describe
separator Optional. Specifies the content placed between array elements. The default is "" (empty string).
array Required. Arrays to be combined into strings.
Similar Functions
Popular Articles