Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

PHP | join() Function

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The join() function is built-in function in PHP and is used to join an array of elements which are separated by a string. Syntax

string join( $separator, $array)

Parameter: The join() function accepts two parameters out of which one is optional and one is mandatory.

  • $separator : This is an optional parameter and is of string type. The values of the array will be join to form a string and will be separated by the $separator parameter provided here. This is optional, if not provided the default is “” (i.e. an empty string)
  • $array : The array whose value is to be joined to form a string.

Return Type: The return type of join() function is string. It will return the joined string formed from the elements of $array. Examples:

Input : join(array('Geeks','for','Geeks')
Output : GeeksforGeeks

Input : join("-",array('Geeks','for','Geeks')
Output : Geeks-for-Geeks

Below program illustrates the working of join() function in PHP: 

PHP




<?php
    // PHP Code to implement join function
     
    $InputArray = array('Geeks','for','Geeks');
     
    // Join without separator
    print_r(join($InputArray));
     
    print_r("\n");
     
    // Join with separator
    print_r(join("-",$InputArray));
?>

Output:

GeeksforGeeks
Geeks-for-Geeks
My Personal Notes arrow_drop_up
Last Updated : 12 Jan, 2023
Like Article
Save Article
Similar Reads
Related Tutorials