PHP while 循环排除数组的第一个
<div id="prettyphoto" align="left"> <a href="http://images.idealer1.com/getimage/999/<?php echo $image['vpid'] ?>.jpg" rel="prettyPhoto[gallery2]"><img src="http://images.idealer1.com/getimage/700/<?php echo $image['vpid'] ?>.jpg" width="100" alt="" /></a>
<ul class="gallery clearfix">
<?php foreach ($images as $image) { ?>
<li><a href="http://images.idealer1.com/getimage/999/<?php echo $image['vpid'] ?>.jpg" rel="prettyPhoto[gallery2]"><img src="http://images.idealer1.com/getimage/100/<?php echo $image['vpid'] ?>.jpg" width="100" alt="" /></a></li>
<? } ?>
</ul>
</div>
我正在尝试采用缩略图的 foreach 循环并排除第一张图像并将其作为更大的图像加载,我似乎无法找出完成此操作的正确方法。
<div id="prettyphoto" align="left"> <a href="http://images.idealer1.com/getimage/999/<?php echo $image['vpid'] ?>.jpg" rel="prettyPhoto[gallery2]"><img src="http://images.idealer1.com/getimage/700/<?php echo $image['vpid'] ?>.jpg" width="100" alt="" /></a>
<ul class="gallery clearfix">
<?php foreach ($images as $image) { ?>
<li><a href="http://images.idealer1.com/getimage/999/<?php echo $image['vpid'] ?>.jpg" rel="prettyPhoto[gallery2]"><img src="http://images.idealer1.com/getimage/100/<?php echo $image['vpid'] ?>.jpg" width="100" alt="" /></a></li>
<? } ?>
</ul>
</div>
I am trying to take this foreach loop of thumbnails and exclude the first image and have it load as a larger image I can't seem to figure out the proper way to accomplish this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
array_shift()
< /strong>:或者如果您不需要对第一张图像的引用,
array_slice()
:还要注意 控制结构的替代语法,这使得阅读 PHP 和 HTML 的混合内容变得更容易(但不相关)到你的问题)。
You could use
array_shift()
:or if you don't need a reference to the first image,
array_slice()
:Also note the use of the alternative syntax for control structures which makes reading the mixture of PHP and HTML a bit easier (but is not related to your problem).
您可以使用 next()、current() 等“手动”迭代数组:
阅读: http://www.php.net/manual/en/function.each.php
使用 array_shift() 你可以“松开”第一个图像(你必须在你完毕)。
使用 array_slice() 会重复数据,这通常是不好的做法。
You can iterate the array "manually", with next(), current(), etc:
Read: http://www.php.net/manual/en/function.each.php
With array_shift() you could "loose" the first image (you have to put it back in after you're done).
With array_slice() you would duplicate data, which is bad practice in general.
你可以使用一些想法:
you can use some idea from this: