PHP join() Function (original) (raw)

Last Updated : 21 Jun, 2023

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,separator, separator,array)

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

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

`` $InputArray = array ( 'Geeks' , 'for' , 'Geeks' );

`` print_r(join( $InputArray ));

`` print_r( "\n" );

`` print_r(join( "-" , $InputArray ));

?>

Output:

GeeksforGeeks Geeks-for-Geeks