The join()
method returns an entire array as a string. The method separates elements with a specified separator; the default separator is a comma (,).
The join method in PHP is used to concatenate an array to return a string. The interesting thing is that the array can be concatenated using a separator. It can be a space (" "), a hyphen (-), a character, etc.
join(separator,array)
separator
: An optional parameter – it refers to the separator used to concatenate a given array.array
: a required parameter – it refers to the array that needs to be converted to a string.<?php$arr1 = array('Welcome','to','Educative!');// array concatenated using a space$var = join(" ",$arr1);echo $var."\n";// array concatenated using a hyphen$var = join("-",$arr1);echo $var."\n";// array concatenated using no separator$var = join($arr1);echo $var."\n";?>
Free Resources