ตัวอย่าง
1 ชั่วโมง 30 นาที หาร 5 กิโลเมตร = 18 นาที/กิโลเมตร
ต้องกำหนดตัวแปลยังไงคะ
ต้องการหารเวลากับจำนวนเต็มแล้วผลออกมาเป็นเวลาต้องทำยังไงคะ
Moderator: mindphp, ผู้ดูแลกระดาน
-
- PHP Super Hero Member
- โพสต์: 680
- ลงทะเบียนเมื่อ: 07/12/2016 10:54 am
ต้องการหารเวลากับจำนวนเต็มแล้วผลออกมาเป็นเวลาต้องทำยังไงคะ
The truth is not as elegant as the idea.
- thatsawan
- PHP VIP Members
- โพสต์: 28508
- ลงทะเบียนเมื่อ: 31/03/2014 10:02 am
- ติดต่อ:
-
- PHP Super Hero Member
- โพสต์: 680
- ลงทะเบียนเมื่อ: 07/12/2016 10:54 am
Re: ต้องการหารเวลากับจำนวนเต็มแล้วผลออกมาเป็นเวลาต้องทำยังไงคะ
ไม่คะ อยากได้แบบนี้ค่ะ แต่จะทำแค่เป็นกิโลเมตร
http://www.coolrunning.com/engine/4/4_1/96.shtml
http://www.coolrunning.com/engine/4/4_1/96.shtml
The truth is not as elegant as the idea.
- Jubtot Kkn
- PHP Newbie
- โพสต์: 4
- ลงทะเบียนเมื่อ: 21/04/2017 4:23 pm
Re: ต้องการหารเวลากับจำนวนเต็มแล้วผลออกมาเป็นเวลาต้องทำยังไงคะ
<?php
$str_time = "01:30:00"; // hours minutes seconds
$str_distance = 5; // 5 km.
$str_time = preg_replace("/^([\d]{1,2})\:([\d]{2})$/", "00:$1:$2", $str_time);
sscanf($str_time, "%d:%d:%d", $hours, $minutes, $seconds);
$time_seconds = $hours * 3600 + $minutes * 60 + $seconds;
$minperkm = ($time_seconds/$str_distance)/60;
echo "min/km = ".$minperkm." minutes/km ";
?>
$str_time = "01:30:00"; // hours minutes seconds
$str_distance = 5; // 5 km.
$str_time = preg_replace("/^([\d]{1,2})\:([\d]{2})$/", "00:$1:$2", $str_time);
sscanf($str_time, "%d:%d:%d", $hours, $minutes, $seconds);
$time_seconds = $hours * 3600 + $minutes * 60 + $seconds;
$minperkm = ($time_seconds/$str_distance)/60;
echo "min/km = ".$minperkm." minutes/km ";
?>
ติดตาม BLOG : http://jubexchange.blogspot.com/
ผู้ใช้งานขณะนี้
สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 126