Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.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_Laravel - Fatal编程技术网

Php 进行计算时出现未定义的变量错误

Php 进行计算时出现未定义的变量错误,php,laravel,Php,Laravel,我有一个web应用程序,我正在拉维尔为一家清洁公司重建 1) 我将参数传递到URL路由 http://127.0.0.1:8000/book?bed_range=1&bath_range=1&percentage_range=0&duration_range= 2) 它进行以下计算: $bedroomCostFactor = [0, 30, 60, 90, 120, 150]; $bathroomCostFactor = [0, 20, 40, 60,

我有一个web应用程序,我正在拉维尔为一家清洁公司重建

1) 我将参数传递到URL路由

http://127.0.0.1:8000/book?bed_range=1&bath_range=1&percentage_range=0&duration_range=
2) 它进行以下计算:

    $bedroomCostFactor = [0, 30, 60, 90, 120, 150];
    $bathroomCostFactor = [0, 20, 40, 60, 80, 100];
    $percentageFactor = [0, 5, 15, 10, 20];    

    if (isset($bed_range) && !empty($bed_range)) {

    if ($bed_range == 1) {
        $bed_cost = $bedroomCostFactor[0];
    } else if ($bed_range == 2){
        $bed_cost = $bedroomCostFactor[1];
    } else if ($bed_range == 3){
        $bed_cost = $bedroomCostFactor[2];
    } else if ($bed_range == 4){
        $bed_cost = $bedroomCostFactor[3];
    } else if ($bed_range == 5){
        $bed_cost = $bedroomCostFactor[4];
    } else if ($bed_range == 6){
        $bed_cost = $bedroomCostFactor[5];
    }
    }

    if(isset($bath_range) && !empty($bath_range)) {
    if ($bath_range == 1) {
        $bath_cost = $bathroomCostFactor[0];
    } else if ($bath_range == 2){
        $bath_cost = $bathroomCostFactor[1];
    } else if ($bath_range == 3){
        $bath_cost = $bathroomCostFactor[2];
    } else if ($bath_range == 4){
        $bath_cost = $bathroomCostFactor[3];
    } else if ($bath_range == 5){
        $bath_cost = $bathroomCostFactor[4];
    } else if ($bath_range == 6){
        $bath_cost = $bathroomCostFactor[5];
    }
    }

    if(isset($percentage_range) && !empty($percentage_range)) {

    if ($percentage_range == 0) {
        $percentage_cost = $percentageFactor[0];
    } else if ($percentage_range == 5){
        $percentage_cost = $percentageFactor[1];
    } else if ($percentage_range == 15){
        $percentage_cost = $percentageFactor[2];
    } else if ($percentage_range == 10){
        $percentage_cost = $percentageFactor[3];
    } else if ($percentage_range == 20){
        $percentage_cost = $percentageFactor[4];
    }

}

$subtotal = "100.00";

$tax = number_format($subtotal * .0725, 2);
$total = $subtotal + $tax;
$discount = number_format(($subtotal * $percentage_cost) / 100, 2);
出于某种原因,当我将代码迁移到Laravel时,它不再工作,它开始说$折扣和$percentage_成本等变量是未定义的


在我以前的应用程序中,计算结果与您预期的一样运行良好。为什么它不能在Laravel中工作?

我必须删除if条件

if(isset($percentage_range) && !empty($percentage_range)) {

此代码在您的Laravel应用程序中的何处?这是否包含在控制器方法、服务或其他内容中?是否确定
$percentage\u cost
始终定义为条件语句的结果?
$percentage\u range
可能是0、5、10、15或20以外的值。代码包含在视图中。是的,我相信它总是被定义的,因为当我将代码迁移到Laravel时,出于某种原因,我总是传入计算$percentage\u成本的$percentage\u range
。新代码在哪里?事实上,我没有看到任何计算结果。