我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

格式化并获取php中的总时间[关闭]

i got this code working on a string like '4-5' and '1-7'

$times = explode("-", $time);
$thpw += ($times[1]- $times[0]);

the problem is when there are multiple time formats like this..

1-2, 5-6
or
8-12, 1-2, 4-5, 6-7

how should I capture the time using that?

Use explode for that too,

$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.

近期文章

  • 找到数组中最长的匹配字符串
  • 在php中调用存储过程(返回两个表)
  • Jquery Alert PHP变量
  • 在同一页面内将变量从JS传递给PHP [关闭]
  • 如何处理时区
  • 将文件附加到电子邮件
  • PHP preg_replace多个url链接
  • PHP在html中操作select?
  • 将数组中的数组移动到父数组php
  • 没有从数据库中选择正确的ID
  • 在mysql查询中添加指向表的链接?
  • 参数号无效:参数未定义[关闭]
  • 重定向网址无法正常工作
  • 类存储库不存在
  • SQL查询从另一个表中获取数据
  • 在首页上隐藏页眉和页脚,但在其他页面上显示EDITED
  • 调用未定义的函数ldap_control_paged_results()
  • 是否有任何快速SQL查询删除重复行[重复]
  • 电子邮件中的换行符不会中断行,但会显示在消息文本中
  • 如何查找多个.change()事件到使用AJAX操作的项目

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华