How to take all the result of a for, and make it become a single variable

1

Let's say I have a for! And that the result of the for is "1 2 3 4 5 6", but each number is a line !!

How do I get all these lines and make it a single variable?

    
asked by anonymous 29.09.2015 / 05:27

1 answer

2

You can do this through a string, concatenating the values with .= or the numbers are all together.

<?php

$arr = range(1,6);
$str = '';
foreach($arr as $item){
    $str .= ' '.$item;
}

echo $str;

Example - ideone

    
29.09.2015 / 05:38