Forum Moderators: coopster
basically I have 3 rows named
row1
row2
row3
now, my code is in a loop so I am not sure how to tell it to call row 1 then 2 then 3, the loop only runs 3 times.
I was trying something like this
$row['row$x']
Which obviously didnt work so I am confused anyone be of any help?
Thanks
Turk
Do you mean something like this:
$row1 = "some text";
$row2 = "some more text";
$row3 = "some random text of doom";
$row = array($row1, $row2, $row3);
for($i = 0; $i < 3; $i++)
{
echo $row[$i]."<br>";
}
//instead of echoing this you can use it for something else
Other than this im really not sure what you are asking
Hope this helps
eelix
I was trying something like this$row['row$x']
Which obviously didnt work so I am confused anyone be of any help?
it will work while using double quotation marks:
$row["row$x"], because only within double quoted string variables will be expanded. it's called variable parsing [php.net].
$row1 = "some text";
$row2 = "some more text";
$row3 = "some random text of doom";
$row = array($row1, $row2, $row3);
for($i = 1; $i <= count($row); $i++)
{
echo "<option value=\"$row[$i]\">$row[$i]</option>";
}
Not to be rude or anything, but i don't understand why you would start the index variable ($i) at 1 because then the first value in the array won't be used. If i am looking at this entirely the wrong way please let me know.
Thank you in advance...
eelix
$row1 = "some text<br>";
$row2 = "some more text<br>";
$row3 = "some random text of doom<br>";
for($i=1; $i <= 3; $i++){
echo ${row.$i};
}
*At least, if I understood the problem correctly. ;)
i don't understand why you would start the index variable ($i) at 1
You didn't define a $row0. Your loop incrementor(?) begins at zero. for($i = 0; $i < 3; $i++). The first iteration will produce an empty result (possibly an error, I haven't checked). You will never echo $row3.
echo $row[0];
echo $row[1];
echo $row[2];
Quoted from [us2.php.net...]
"When index is omitted, an integer index is automatically generated, starting at 0."
That would mean that the index should start at 0 and not 1, and going up to 3 will give an error. It would have to start at 1 if the array was defined like
$row = array(1 => $text1, $text2, $text3); hmmm....oh well...
eelix
It would have to start at 1 if the array was defined like
$row = array(1 => $text1, $text2, $text3);
just in case you really define an array like this, then a print_r($row); [php.net] will tell you the truth:
Array (
[1] => some text
[2] => some more text
[3] => some random text of doom
)
you're right! ;)