dongrang9300 2010-11-19 13:18
浏览 29
已采纳

PHP - 变量变量或变量数组()用于()

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!!

  • 写回答

6条回答 默认 最新

  • dongzhouhao4316 2010-11-19 13:33
    关注

    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>';
    ?>
    

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序