I want to make in html page like this below:
<a href="1" class="currentvid"></a>
<a href="2"></a>
<a href="3"></a>
But, I don't want to write them all one by one, because the number(1, 2, 3) are from $number
variable and it can be more than 3.
Use a for
loop:
for ($i = 1; $i <= $number; $i++) {
echo "<a href='$i'";
if ($i == $currentvid) {
echo " class='currentvid'";
}
echo "></a>";
}
Try this:
<?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>";
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.