Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.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通过api收到价格后如何调整价格_Php - Fatal编程技术网

PHP通过api收到价格后如何调整价格

PHP通过api收到价格后如何调整价格,php,Php,后台-页面连接到api以获取一些信息。当它显示在页面上时,我需要在夏季将价格提高1.25% 这是来自API的信息:(这很有效) 这是页面的显示部分: <p class="fleet-list-item_rates"> <strong>Sept. 15th – May 14th</strong>:&nbsp;&nbsp; <?php print(money_format('%.2n', $vehicle["price"]["day

后台-页面连接到api以获取一些信息。当它显示在页面上时,我需要在夏季将价格提高1.25%

这是来自API的信息:(这很有效)


这是页面的显示部分:

<p class="fleet-list-item_rates">
   <strong>Sept. 15th – May 14th</strong>:&nbsp;&nbsp; <?php print(money_format('%.2n', $vehicle["price"]["day"] / 100)) ?> / day &nbsp;&nbsp;&nbsp;<em>*7 Days or More 14% Discount</em>
   <?php
   foreach($seasons as $season):
       $price = find_price_within_season($season, $vehicle["id"]);
       if ($price):
         $day = $price["day"] / 100.0;
       else:
         $day = ($vehicle["price"]["day"] / 100.0) * ($season["adjust_price_percent"] / 100);
       endif;
       ?>
       <br>
       <strong><?php print(friendly_date($season["from"])) ?> - <?php print(friendly_date($season["to"])) ?></strong>:&nbsp;&nbsp; <?php print(money_format('%.2n', $day)) ?> / day
<?php endforeach; ?>
</p>

9月15日至5月14日:/day*7天或以上14%的折扣
-:/day

这是我的编辑,添加了1.25%的附加值

    <p class="fleet-list-item_rates">
       <strong>May 14th - Sept. 15th</strong>:&nbsp;&nbsp; <?php print(money_format('%.2n', $vehicle["price"]["day"] / 100)) ?> / day &nbsp;&nbsp;&nbsp;<em>*7 Days or More 10% Discount</em>
<?php
    $percentagechange = 1.25;
    $numberToAdd = ($price / 100) * $percentagechange;
    $newNumber = $price + $numberToAdd;
    $newNumber = ["newNumber"];
    foreach($seasons as $season):
    $price = find_price_within_season($season, $vehicle["id"]);
    if ($price):
        $day = $price["day"] / 100.0;
    else:
        $day = ($vehicle["price"]["day"] / 100.0) * ($season["newNumber"] / 100);
    endif;
?>
    <br>
    <strong><?php print(friendly_date($season["from"])) ?> - <?php print(friendly_date($season["to"])) ?></strong>:&nbsp;&nbsp; <?php print(money_format('%.2n', $day)) ?> / day
<?php endforeach; ?>
</p>

5月14日至9月15日:/day*7天或以上10%的折扣
-:/day


只是不知道如何将该值增加1.25%。

似乎你在计算之前增加的百分比 有实际的价格

关于如何进行计算:

$percentagechange = 1.25;
$numberToAdd = ($price * $percentagechange) / 100;
$newNumber = $price + $numberToAdd;
// Get rid of the following. It is overwriting your calculated number.
//$newNumber = ["newNumber"];

如何更改代码:

if ($price):
    $day = $price["day"] / 100.0;
else:
    $day = ($vehicle["price"]["day"] / 100.0) * ($season["newNumber"] / 100);
endif;
// At this point $day contains the price per day
// Increase price by 1.25%
$day *= 1.0125;
?>
<br>
<strong>
  <?= friendly_date($season["from"]) ?> - <?= friendly_date($season["to"]) ?>
</strong>
  :&nbsp;&nbsp; <?= money_format('%.2n', $day) ?> / day
<?php endforeach; ?>
if($price):
$day=$price[“day”]/100.0;
其他:
$day=($vehicle[“price”][“day”]/100.0)*($seasure[“newNumber”]/100);
endif;
//此时,$day包含每天的价格
//提价1.25%
$day*=1.0125;
?>

- :/天

请注意,我已将代码更改为使用
OK。很抱歉,我仍然无法完成此工作。很可能我把它放错地方了。在代码中,一旦我得到$newNumber,如何替换代码中的$price?我以为您正在尝试学习如何进行计算。我对答案做了一些修改,希望能回答这个问题。
$newNumber = $price * 1.0125;
if ($price):
    $day = $price["day"] / 100.0;
else:
    $day = ($vehicle["price"]["day"] / 100.0) * ($season["newNumber"] / 100);
endif;
// At this point $day contains the price per day
// Increase price by 1.25%
$day *= 1.0125;
?>
<br>
<strong>
  <?= friendly_date($season["from"]) ?> - <?= friendly_date($season["to"]) ?>
</strong>
  :&nbsp;&nbsp; <?= money_format('%.2n', $day) ?> / day
<?php endforeach; ?>