I have this code that generates an HTML table with php:
<?php
include("numbers2.php");
echo '<table border="1">';
echo '<tr>';
for ($i = 1; $i <= 9; $i++) {
if($a1_pos_txt !== TRUE) {
echo "<td>" . $numbers["a" . $i . "_pos"] . "</td>";
} else {?>
<?php
echo '<td><input type="text" name="a' . $i . '_post" size="1" maxlength="1" /></td>';
?>
<?php } }?>
What I need to do is modify the $a1_post_txt
variable so that it when the foor loops I will get instead of $a1_pos_txt
every time:
$a1_pos_txt
.
.
$a9_pos_txt
I it basically what I did with $numbers["a" . $i . "_pos"]
and with name="a' . $i . '_post"
but now that the variable is inside another variable I don´t know how to do this.
I hope it is clear enough, if no please ask for any clarifications needed.
Thanks in advance!!
Instead of variable use array. In your array will contain values like true or flase, which were earlier in $a1_pos_txt......$a9_pos_txt
$arrOfValues[1] = TRUE;
$arrOfValues[2] = FALSE;
......
.....
...
$arrOfValues[9] = TRUE;
So code will look like this
<?php
include("numbers2.php");
echo '<table border="1">';
echo '<tr>';
for ($i = 1; $i <= 9; $i++) {
if($arrOfValues[$i] !== TRUE) {
echo "<td>" . $numbers["a" . $i . "_pos"] . "</td>";
} else {?>
<?php
echo '<td><input type="text" name="a' . $i . '_post" size="1" maxlength="1" /></td>';
?>