简体   繁体   English

PHP回显行X倍不同的文本

[英]PHP echo line X times different text

Title might not make complete sense, couldn't think of a way to explain it so I will do a mock PHP example. 标题可能没有完全意义,无法考虑一种解释方式,因此我将模拟一个PHP示例。

<?php
$startNumber = 1;
$endNumber = 15;
$fileExt = '.jpg';
?>

And then on the page it will echo from the $startNumber to the $endNumber in something like a foreach 然后在页面上,它会以类似foreach的方式从$ startNumber到$ endNumber回显

<?php echo("<img src=\"#.jpg\">"); ?>

Hope this is making sense... 希望这是有道理的...

I'd also like to point out that the numbers < 10 start with a 0 so it will need to be in the image source link. 我还要指出,数字<10以0开头,因此它必须位于图像源链接中。

echo is not a function, it's a language construct. echo不是函数,它是一种语言构造。 Don't use (). 不要使用()。

Also you need to use a loop like for() to do that (Also see sidenote of Fred -ii). 同样,您需要使用for()之类的循环来执行此操作(另请参见Fred -ii的旁注)。

$endNumber = 15;
for($i = 1; $i <= $endNumber; $i++) {
    if($i < 10) {
        $i = "0".$i;
    }
    echo "<img src=\"".$i.".jpg\" />";
}

If this is not what you asked, add more information. 如果这不是您要的内容,请添加更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM