使用下面的代码我有一个问题,我得到第1和第2行就好了,但第3行和下一行只会出现此错误:
注意:未定义的偏移量:C:\ xampp \ htdocs \ h_php \ addTimes.php中的1 第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++;
}
?>
答案 0 :(得分:0)
根据你的逻辑,
这是错误
SublimeLinter: golint activated: /Users/gianmarco/Documents/Dev/Go/bin/golint
Emmet: No need to update PyV8
SublimeLinter: chdir not set or invalid, using /Users/gianmarco/Documents/Dev/Go/src/github.com/gianmarco/hello
SublimeLinter: golint: hello.go guessed GOPATH=/Users/gianmarco/Documents/Dev/Go
SublimeLinter: golint: hello.go ['/Users/gianmarco/Documents/Dev/Go/bin/golint']
Package Control: Skipping automatic upgrade, last run at 2015-11-28 11:58:34, next run at 2015-11-28 12:58:34 or after
SublimeLinter: chdir not set or invalid, using /Users/gianmarco/Documents/Dev/Go/src/github.com/gianmarco/hello
SublimeLinter: golint: hello.go guessed GOPATH=/Users/gianmarco/Documents/Dev/Go
SublimeLinter: golint: hello.go ['/Users/gianmarco/Documents/Dev/Go/bin/golint']
SublimeLinter: chdir not set or invalid, using /Users/gianmarco/Documents/Dev/Go/src/github.com/gianmarco/hello
SublimeLinter: golint: hello.go guessed GOPATH=/Users/gianmarco/Documents/Dev/Go
SublimeLinter: golint: hello.go ['/Users/gianmarco/Documents/Dev/Go/bin/golint']
此行应为
echo $day1hours = "$hours" . 'Hours ' . "$minutes" . ' Mints';
输出:
echo $day1hours = $hours . ':'.$minutes;
请参阅演示here
答案 1 :(得分:0)
这不是错误,只是一个通知,告诉您在代码的第19行,您使用的是不存在的偏移量。
假设您发布的代码已完成,则表示此行无法正常运行:
$totalmins += $day2[1];
因为$day2
数组似乎没有2个元素。
您是否检查$timearry
中的所有元素是否格式正确为“H:m”?