dqab0824 2015-11-28 11:14
浏览 63
已采纳

注意:未定义的偏移量:第19行的C:\ xampp \ htdocs \ h_php \ addTimes.php中的1

With the below code I have a problem where I'm getting the 1st and 2nd row just fine, but the 3rd and next rows only give this error:

Notice: Undefined offset: 1 in C:\xampp\htdocs\h_php\addTimes.php on line 19.

<?php
$timearry="";
$timearry=array("1:10","1:40","1:20","0:50");
$i=0;
$day1hours="";
foreach($timearry as $times){
    if($i==0){
        echo $day1hours= $times;
        echo "<br>";
    }else{
        $day2hours = $times;
        $day1=array();
        $day1 = explode(":", $day1hours);
        $day2 = explode(":", $day2hours);
        $totalmins = 0;
        $totalmins += $day1[0] * 60;
        $totalmins += $day1[1];
        $totalmins += $day2[0] * 60;
        $totalmins += $day2[1];
        $hoursTotal = $totalmins / 60;
        $hours=0;
        $hours = explode(".", $hoursTotal);
        $hours= $hours[0];
        $minutes = $totalmins % 60;
        echo $day1hours = "$hours".'Hours '."$minutes".' Mints';
        echo "<br>";
    }
    $i++;
}
?>
  • 写回答

2条回答 默认 最新

  • dtz46697 2015-11-28 11:21
    关注

    According to your logic,

    Here is the mistake

    echo $day1hours = "$hours" . 'Hours ' . "$minutes" . ' Mints';
    

    This line should be

    echo $day1hours = $hours . ':'.$minutes;
    

    Output:

    1:10
    2:50
    4:10
    5:0
    

    See demo here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题