【问题标题】:How to echoing the variable and loop?如何回显变量和循环?
【发布时间】:2015-03-31 02:41:10
【问题描述】:

我想在下面的html页面中制作:

<a href="1" class="currentvid"></a>
<a href="2"></a>
<a href="3"></a>

但是,我不想一一写出来,因为数字(1,2,3)来自$number变量,它可以超过3。

【问题讨论】:

  • 然后向我们展示您当前拥有的代码

标签: php html loops for-loop echo


【解决方案1】:

使用for 循环:

for ($i = 1; $i <= $number; $i++) {
    echo "<a href='$i'";
    if ($i == $currentvid) {
        echo " class='currentvid'";
    }
    echo "></a>";
}

【讨论】:

    【解决方案2】:

    试试这个:

    <?php
    $href="1";
    for($i=1;$i<4;$i++){
      if($href==$i){
       echo "<a href=\"$href\" class=\"currentvid\">$i</a>";
      }else{
       echo "<a href=\"$href\">$i</a>";
      }
    }
    ?>
    

    【讨论】:

      【解决方案3】:
      $i = 1;
              foreach ($number as $k)
              {
                  if($i == 1)
                  {
                      echo "<a href=\"$href\" class=\"currentvid\">$i</a>";
                  }
                  else
                  {
                      echo "<a href=\"$href\">$i</a>";
                  }
              }
          }
      

      【讨论】:

        猜你喜欢
        • 2015-03-22
        • 1970-01-01
        • 2019-07-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-03-29
        • 1970-01-01
        • 2018-03-23
        相关资源
        最近更新 更多