I remember there was an easy way without a for each to reconstruct an array into a string.
EG:
1 > my
2 > name
3 > is
4 > sam
into
$string = "my name is sam" (with spaces in between).
How was this done with php?
You just need to implode the string:
$array = array("my", "name", "is", "sam");
$string = implode(' ', $array);
echo $string; // "my name is sam"
Try this:
<?php
$array = array('lastname', 'email', 'phone');
$comma_separated = implode(",", $array);
print $comma_separated; // lastname,email,phone
?>
$one_per_line = implode(PHP_EOL, $array);You should use the implode method. You can read more about it on the following link: http://php.net/manual/en/function.implode.php.
Your code would be something like:
$string = implode(" ", $array);