php foreach loop display all data
<p>I have dump problem with foreach loop... 
I want to display all data in foreach, example:</p>

<pre><code>$data[1] = "Hello"; 
$data[2] = "my"; 
$data[3] = "World";
</code></pre>

<p>I use this script and work</p>

<pre><code>for($i=1; $i&lt;3; $i++){
        $mydata = $data[$i];
        echo $mydata; }
</code></pre>

<p>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, <em>World</em></p>

<p>Why? How to include all data from variable</p>