如何结合两个PHP计算

时间:2016-11-23 10:39:33

标签: php

如何将某个php包含为php计算的附加功能

这是基本代码

<?php echo (str_replace('.',',',round((str_replace(',','.',(str_replace('€','',$discount['discountedPrice'])))*1.2),2)))." Eur"; ?>

并想添加以下内容:

(str_replace('.',',',round((str_replace(',','.',(str_replace('€','',$discount['discountAmount'])))*0.2),2)))

所以我想添加(+),看起来像这样,但不知道如何把它:

(str_replace('.',',',round((str_replace(',','.',(str_replace('€','',$discount['discountedPrice'])))*1.2),2))) + (str_replace('.',',',round((str_replace(',','.',(str_replace('€','',$discount['discountAmount'])))*0.2),2)))

1 个答案:

答案 0 :(得分:0)

你去了:

<?php 

$value120Percent = round(removeEuroChangeDecimal($discount['discountedPrice']) * 1.2, 2);
# or if you really don't need rounding
# $value120Percent = removeEuroChangeDecimal($discount['discountedPrice']) * 1.2;
$value20Percent = round(removeEuroChangeDecimal($discount['discountAmount']) * 0.2, 2);
# or if you really don't need rounding
# value20Percent = removeEuroChangeDecimal($discount['discountAmount']);

# change the fourth parameter to set thousands separator (to e.g. a space)
echo number_format($value120Percent + $value20Percent, 2, ',', '');

function removeEuroChangeDecimal($value) {
    return str_replace(',', '.', str_replace('€','', $value));
}