如何回显变量和循环


How to echoing the variable and loop?

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

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

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

使用for循环:

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

试试这个:

<?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>";
  }
}
?>
$i = 1;
        foreach ($number as $k)
        {
            if($i == 1)
            {
                echo "<a href='"$href'" class='"currentvid'">$i</a>";
            }
            else
            {
                echo "<a href='"$href'">$i</a>";
            }
        }
    }