Basic Question.....I think?
Posted: Thu Jul 12, 2007 7:06 am
Hi,
I'm relatively new to php been doing it a couple of weeks and i have a what i think is a basic question. Here is my code.
and the output is
why doesnt the last loop know what's inside $newArray[] is when it is declared and assigned above.
thanks
Greg
I'm relatively new to php been doing it a couple of weeks and i have a what i think is a basic question. Here is my code.
Code: Select all
<?php
$max = $_POST["max"];
$newArray = array();
$print = FALSE;
for($i=0;$i<$max;$i++)
{
$originalArray[i] = $_POST["text$i"];
if($i == $max - 3 && $print == FALSE)
{
$newArray[0] = $originalArray[i];
//echo " $newArray[0] <br>";
}
if($i == $max - 2 && $print == FALSE)
{
$newArray[1] = $originalArray[i];
//echo " $newArray[1] <br>";
}
if($i == $max - 1 && $print == FALSE)
{
$newArray[2] = $originalArray[i];
//echo " $newArray[2] <br>";
$print = TRUE;
$i = 0;
}
if($i < $max - 3 && $print == FALSE)
{
for($k=$i+3;$k<$i+4;$k++)
{
$newArray[k]=$originalArray[i];
//echo " $newArray[k] ";
}
}
/*why doesn't this loop know what's inside newArray is when it is declared and assigned above*/
if($print == TRUE)
{
echo "$i = $newArray[i]";
if((($i+1) % 3) == 0)
{
echo "<br>";
}
}
}
?>Code: Select all
0 = 1 = 2 =
3 = 4 = 5 =
6 = 7 = 8 =
9 = 10 = 11 =
12 = 13 = 14 =
15 = 16 = 17 =
18 = 19 = 20 =
21 = 22 = 23 =
24 = 25 = 26 =thanks
Greg