Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php计算器函数变量和时间_Php - Fatal编程技术网

php计算器函数变量和时间

php计算器函数变量和时间,php,Php,您好,我正在尝试创建一个php计算器,它基本上可以实现以下功能: $price_m_Fuengirola = 11.00; /* number of people */ $car1 = 0.00; /* 1-4 */ $car2 = 50.00; /* 4-8 */ $car3 = 70.00; /* 8-12 */ $car4 = 90.00; /* 12-16 */ /* Calculator */ date_default_timezone_set('GMT'); //echo

您好,我正在尝试创建一个php计算器,它基本上可以实现以下功能:

$price_m_Fuengirola = 11.00;

/* number of people */

$car1 = 0.00; /* 1-4 */
$car2 = 50.00; /* 4-8 */
$car3 = 70.00; /* 8-12 */
$car4 = 90.00; /* 12-16 */

/* Calculator */

date_default_timezone_set('GMT');

//echo $newTime;

echo $price_m_Fuengirola."<br />";

echo $car2."<br />";

function timeCalc(){
$newTime = date("H:i", time());

if ($newTime < "18:56"){

    echo 20.00;
    //echo "<br />this is more time";

} else {

    echo 6.00;
    //echo "this is more time";

}
}


$timeCalc = timeCalc();

echo $timeCalc."<br />";

$total = $price_m_Fuengirola + $car2 + $timeCalc."<br /><br />";

echo $total;`
$price\u m\u Fuengirola=11.00;
/*人数*/
$car1=0.00;/*1-4 */
$car2=50.00;/*4-8 */
$car3=70.00;/*8-12 */
$car4=90.00;/*12-16 */
/*计算器*/
日期默认时区设置('GMT');
//echo$newTime;
echo$price_m_Fuengirola.“
”; echo$car2.“
”; 函数timeCalc(){ $newTime=日期(“H:i”,time()); 如果($newTime<“18:56”){ 回声20.00; //回声“
这是更多的时间”; }否则{ 回声6.00; //回声“这是更多的时间”; } } $timeCalc=timeCalc(); echo$timeCalc.“
”; $total=$price_m_Fuengirola+$car2+$timeCalc.“

”; echo$总计`

其背后的逻辑是,如果一个人在x时间之前预订了出租车,那么他们将被收取x费用,否则他们将被收取x费用(我计划在我设法使其正常工作时进行更改),问题是价格将被添加到汽车价格中,而不是功能价格输出中。在函数中,我试图只回显一个不代表时间的数字,那么我是否遗漏了一些内容?

以下是我的具体做法:

<?php

function rateOffset($now, $cutoff){
    if ($now < strtotime($cutoff)){
        return 20.00;
    } else {
        return 6.00;
    }
}

$cutoff = "18:56";

for ($i = 0; $i < 24; $i++) {
    $now = strtotime("$i:00");
    $rateCalc = rateOffset($now, $cutoff);
    echo date('H:i', $now)." = $rateCalc\n";
}

?>

感谢Jared Farrish提供的信息,需要编辑它的人不是php人员,那么我们是否可以像我一样让它更可读?
00:00 = 20
01:00 = 20
02:00 = 20
03:00 = 20
04:00 = 20
05:00 = 20
06:00 = 20
07:00 = 20
08:00 = 20
09:00 = 20
10:00 = 20
11:00 = 20
12:00 = 20
13:00 = 20
14:00 = 20
15:00 = 20
16:00 = 20
17:00 = 20
18:00 = 20
19:00 = 6
20:00 = 6
21:00 = 6
22:00 = 6
23:00 = 6