Q:

php foreach loop display all data

I have dump problem with foreach loop... 
I want to display all data in foreach, example:
$data[1] = "Hello"; 
$data[2] = "my"; 
$data[3] = "World";

I use this script and work
for($i=1; $i<3; $i++){
        $mydata = $data[$i];
        echo $mydata; }

This is ok, no problem. 
But when I want to include $mydata in next script (for saving in txt), he shows only the last word, World
Why? How to include all data from variable

A:

Try this : 
$mydata = '';
for($i=1; $i<3; $i++){
   $mydata .= $data[$i];
}
echo $mydata;

