Edward144 Edward144 - 26 days ago 9
PHP Question

PHP - For loop store all array values as one long string

I need to store each value in an array as one single string. Is it possible to do this?

I have tried using a for loop to achieve this:

for($count = 0; $count < $totalArray; $count++) {
$x = $array[$count];
}


I'm not sure why I thought this would work. it will obviously, keep changing the value and end up as the last value in the array. But can anyone tell me if there is a way to do this?

Answer

You need to add to the previous total, not set it:

$x .= $array[$count];