Method 1: Using implode() Method: The implode() method is used to join an array of elements that are separated by a string. Joining can be done with or without separator.
Syntax:
string implode($separator, $array)
//joining the values of an array
//function to get the string
function get_string($arr){
//using implode ()function to join without seperator
echo implode($arr);
//using implode() function to join with seperator
echo implode("-",$arr);
}
//given array
$arr=array('company','website',"\n");
//function calling
$str=get_string($arr);
?>
Method 2: Using join() Method: The join() method is used to join an array of elements that are separated by a string. Joining can be done with or without separator. The join() method is same as the implode() method.
Syntax:
string join($separator, $array)
<?php
//joining the values of an array
//function to get the string
function get_string($arr){
//using implode ()function to join without seperator
echo join($arr);
//using implode() function to join with seperator
echo join("-",$arr);
}
//given array
$arr=array('company','website',"\n");
//function calling
$str=get_string($arr);
?>