How do I merge all the array items into a single string?
Try this from the PHP manual (implode):
<?php
$array = array('lastname', 'email', 'phone');
$comma_separated = implode(",", $array);
echo $comma_separated; // lastname, email, and phone
// Empty string when using an empty array:
var_dump(implode('hello', array())); // string(0) ""
?>
foreach($array as $key => $value) {
$string .= $value .' ';
}
You can use join. It's an alias for implode, and in my opinion more readable:
$fruits = array('apples', 'pears', 'bananas');
echo join(',', $fruits);
join(" -- ", Array("a", "b")) == "a -- b"
actually join is an alias for the implode function.
$array1 = array(
"one",
"two",
)
$array2 = array(
"three",
"four",
)
$finalarr = array_merge($array1, $array2);
$finalarr = implode(",", $finalarr);
will produce this one,two,three,four
$array= array( "Alfred Hitchcock", "Stanley Kubrick", "Martin Scorsese", "Fritz Lang" );
$string="";
foreach ( $tempas $array) {
$string=$string.",".$temp;
}