Is there something I need to know about creating an array in a for loop? When doing this I can only call to the array while I'm in the loop. Here's some sample code showing what I mean.
<?
echo "<b>Inside Loop</b><br>";
for($i=0; $i < 3; $i++) {
$story_id_array = array($i => $i);
echo "$i = ".$story_id_array[$i]."<br>";
}
echo "<p><b>Outside Loop</b>";
echo "<br>0 = ".$story_id_array[0];
echo "<br>1 = ".$story_id_array[1];
echo "<br>2 = ".$story_id_array[2];
shownums($story_id_array);
function shownums($story_id_array){
echo "<p><b>Inside Function</b>";
echo "<br>0 = ".$story_id_array[0];
echo "<br>1 = ".$story_id_array[1];
echo "<br>2 = ".$story_id_array[2];
}
?>
The part that has me so confused is the last variable in the array is available outside the loop, but nothing else is? Here are the results of the above code.
Inside Loop
0 = 0
1 = 1
2 = 2
Outside Loop
0 =
1 =
2 = 2
Inside Function
0 =
1 =
2 = 2
Thanks