douju5933 2013-07-20 09:23
浏览 113

获取数组中的下一个值

I have this array:

<?php
$arrFiles = array_diff(scandir("scans", 0), array(".", ".."));
$arrFiles = array_values($arrFiles);
?>

that prints fine with this:

<?php 
print_r(array_values($arrFiles));
?>

and these buttons that I want to use to skip from one image to the prev or next:

  <a href="javascript:skipLeft()"><img src="/ico/skip_left.gif" width="12" height="12" hspace="1" vspace="1" />skip left</a> / 
  <a href="javascript:skipRight()"><img src="/ico/skip_right.gif" width="12" height="12" hspace="1" vspace="1" />skip right</a>

I probably need some kind of loop, -1 and +1 or prev and next or something.

I've tried so many things. No luck.

Page: http://flamencopeko.net/songs_scans_skip.php

Source: http://flamencopeko.net/songs_scans_skip.txt

  • 写回答

1条回答 默认 最新

  • dongwuzun4630 2013-07-20 09:51
    关注

    You will probably want a loop like this:

    for($i=0; $i < sizeof($arrFiles); $i++)
    {
      echo "<img src=scans/" . $arrFiles[$i] . ">";
    }
    

    to select an image using a page by page technique you could use this:

    if($_GET['p'] >= sizeof($arrFiles)) echo "<img src=scans/" . $arrFiles[sizeof($arrFiles)] . ">";
    else{
      echo "<img src=scans/" . $arrFiles[$_GET['p']] . ">";
    }
    

    use this for links/buttons

    echo "<a href='yourpagename.php?p=" . $_GET['p']+1 . "'>"; // next
    echo "<a href='yourpagename.php?p=" . $_GET['p']-1 . "'>"; // previous
    

    you can use the same if as above to filter out max of array size and obviously use 0 as min array size to cover the low end

    if(!max){ //shownext }
    if(!min){ //showprevious }
    

    note this is not going to work without proper structuring but you can get the idea

    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序