dsue14118 2014-10-17 01: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 11: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条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部