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条)

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)