Hey guys,
Basically I have a really big table with lots of variables all over the place.
eg.
[PHP]
<table>
<tr><td><?php echo( $var1." is ".$var2 ); ?></td></tr>
<tr><td><?php echo( $bar1." is ".$bar2 ); ?></td></tr>
<tr><td><?php echo( $dar1." is ".$dar2 ); ?></td></tr>
<tr><td><?php echo( $sar1." is ".$sar2 ); ?></td></tr>
...
[/PHP]
Now I want to do a for loop which will make the table for me echo-ing the <td> and <tr> aswell, however I want to change the variable name, so something like making an array:
[PHP]$array = array('var', 'bar', 'dar', 'sar');[/PHP]
And then having a for loop with something like:
[PHP]for ( i=0; name1=$array[i]; i++ ) {
echo( "<tr><td>".$nam e.1." is ".$name.2." </td></tr>" );
}[/PHP]
Firstly, is my for loop condition correct? Regardless, my main question is the echo line: How do you add a number (or characters) to the end of a variable name to change what variable it is? Can you?
Basically I have a really big table with lots of variables all over the place.
eg.
[PHP]
<table>
<tr><td><?php echo( $var1." is ".$var2 ); ?></td></tr>
<tr><td><?php echo( $bar1." is ".$bar2 ); ?></td></tr>
<tr><td><?php echo( $dar1." is ".$dar2 ); ?></td></tr>
<tr><td><?php echo( $sar1." is ".$sar2 ); ?></td></tr>
...
[/PHP]
Now I want to do a for loop which will make the table for me echo-ing the <td> and <tr> aswell, however I want to change the variable name, so something like making an array:
[PHP]$array = array('var', 'bar', 'dar', 'sar');[/PHP]
And then having a for loop with something like:
[PHP]for ( i=0; name1=$array[i]; i++ ) {
echo( "<tr><td>".$nam e.1." is ".$name.2." </td></tr>" );
}[/PHP]
Firstly, is my for loop condition correct? Regardless, my main question is the echo line: How do you add a number (or characters) to the end of a variable name to change what variable it is? Can you?
Comment