我让这段代码处理像'4-5'和'1-7'
这样的字符串$times = explode("-", $time);
$thpw += ($times[1]- $times[0]);
问题是当有多种时间格式时......
1-2, 5-6
or
8-12, 1-2, 4-5, 6-7
我应该如何使用它来捕捉时间?
答案 0 :(得分:2)
也可以使用爆炸,
$times = explode(",","8-12, 1-2, 4-5, 6-7");
$thpw = 0;
foreach($times as $time){
$time_arr = explode("-", $time);
$thpw += ($time_arr[1]- $time_arr[0]);
}
echo $thpw; // 7
<强> DEMO 强>