dsue14118 2014-10-17 09:48
浏览 294
已采纳

为数组中的所有元素添加值(php)

I have a query to get an array from a database.

$result = mysqli_query($con,"SELECT `Time_D` from `Schedule` where `Stop` = 1 ");

while ($row = mysqli_fetch_array($result) ) {                         
echo $row['Time_D'] . "<br>";
}

This array ($row) contains a lot of times, if I'm not mistaken.

I now want to add for example 10 minutes to all the elements in the array. How do I do that?

  • 写回答

5条回答 默认 最新

  • douqulv6059 2014-10-18 19:07
    关注

    Well, figured it out myself after all.

    $result = mysqli_query($con,"SELECT `Time_D` from `Schedule` where `Stop` = 1 ");
    
    //get database result
    while ($row = mysqli_fetch_array($result) ) {                         
    $rows[] = $row['Time_D']; //store all the times in one array
    }
    print_r ($rows);
    
    echo "<br>";
    $time_difference=600;
    $i=0;
    
    while (($i) < (count($rows)) ) {
    $rows[$i] = ( strtotime($rows[$i]) ) + ($time_difference); //with timestamps, because, well, php and times...
    $rows[$i] = date('H:i:s', ($rows[$i]) ); // back from timestamp to time
    $i = $i +1;
    }
    print_r($rows);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
  • ¥50 vue router 动态路由问题
  • ¥15 关于#.net#的问题:End Function
  • ¥15 无法import pycausal
  • ¥15 VS2022创建MVC framework提示:预安装的程序包具有对缺少的注册表值的引用
  • ¥15 weditor无法连接模拟器Local server not started, start with?
  • ¥20 6-3 String类定义
  • ¥15 嵌入式--定时器使用
  • ¥20 51单片机学习中的问题