I am pulling data from a query that has the following output: 1 2 3 5
I am converting it into an array like so:
$string = explode("\n", $result);
I know have an array displaying the following:
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 5
)
now I am trying to put that array back into a single string having a | seperator
$test = "";
foreach($string as $key)
{
$test .= $key." | ";
}
however, I am getting the ouput of test:
| 5 |
can somone explain why its not showing what I expect it to show and another way how to produce a single string with a | seperator?
thanks
implode()
is what you want; it does exactly what you're asking for. If you're not seeing that then there's something else going on with your array that you haven't told us. – Spudley May 17 '13 at 15:37