• php拾遗


        //计算库存
        foreach($aGoodsLst as $goodsid => $aGoods)
        {
            $aGoods['price'] = $aGoods['buy']==0?0:($aGoods['buymoney']/ $aGoods['buy']);
            $aGoods['stock'] = $aGoods['buy'] - $aGoods['sell'] + $aGoods['return'];  
            $aGoods['stockmoney'] = $aGoods['stock'] * $aGoods['price']; //库存金额以进价为准 
            
            //重新计算销售金额 
            $aGoods['sell'] = $aGoods['sell'] - $aGoods['return'];  
            $aGoods['sellmoney'] = $aGoods['sellmoney'] - $aGoods['returnmoney'];  
            
            //盈余
            $aGoods['earn'] = $aGoods['sellmoney']-$aGoods['buymoney']; 
            
            extract($aGoods);
            
            $sSql = "UPDATE goods SET buy='$buy',buymoney='$buymoney',stock='$stock',stockmoney='$stockmoney',sell='$sell',sellmoney='$sellmoney',`return`='$return',returnmoney='$returnmoney',earn='$earn' WHERE id=$goodsid";
            $oDb->query($sSql); 
        }

    在for循环中的extract时,如果数组的下标不包含到$buy等后续要使用的变量,会导致使用其他不相关的或者前一次生成的变量,需要特别的注意

  • 相关阅读:
    蛇形填数
    开灯问题
    水仙花数
    C++Primer笔记-----day02
    C++Primer笔记-----day01
    面试智力题
    maven 打包197
    子系统 安装vsftpd197
    office 安装破解197
    oracle 创建多个数据库197
  • 原文地址:https://www.cnblogs.com/yondy/p/2624435.html
Copyright © 2020-2023  润新知