douzhang1852 2015-03-26 13:54
浏览 77
已采纳

PHP将变量传递给函数并丢失值

I am passing some variables to a function to round and add a dollars sign but when the values get into the function they have lost their values.

formatDollars($cost, $taxedCost, $shipping, $total)

function formatDollars($cost, $taxedCost, $shipping, $total) {
    $taxedCost = '$'.round($taxedCost, 2);
    $shipping = '$'.round($shipping, 2);
    $total = '$'.round($total, 2);
    $cost = '$'.round($cost, 2);
    return array($cost, $taxedCost, $shipping, $total);
}

list($cost, $taxedCost, $shipping, $total) = formatDollars();

When I output I get the dollar signs but all my numbers have become zero.

  • 写回答

3条回答 默认 最新

  • douman9420 2015-03-26 17:34
    关注

    I ended up finding the answer to my own quesion

    In the line that I send variables to the function it did not like not having a variable to equal to, so when I ended up saying my variables equalled sending to the function.

    function formatDollars($numberFormatted)
        {
            $numberFormat = '$'.round($numberFormatted, 2);
            return $numberFormat;
        }
        $cost = formatDollars($cost);
        $taxedCost = formatDollars($taxedCost);
        $shipping = formatDollars($shipping);
        $total = formatDollars($total);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog