abcd四个项目收益顺序分别占10%,20%,30%,40%,当有一个项目不存在时则该项目收益归上一个项目,项目a 始终存在,封装一个函数得到abcd的收益;
这题不难,关键点是要想到用数组,这点想到了,那肯定能做出来。
程序代码:
/**
     * 获取项目收益
     * @param null $b
     * @param null $c
     * @param null $d
     * @return array
*/
    function getIncome($b = null, $c = null, $d = null)
    {
        $income = ['a' => 0.1, 'b' => 0.2, 'c' => 0.3, 'd' => 0.4];
        if (!$d) {
            $income['c'] += $income['d'];
            $income['d'] = 0;
        }
        if (!$c) {
            $income['b'] += $income['c'];
            $income['c'] = 0;
        }
        if (!$b) {
            $income['a'] += $income['b'];
            $income['b'] = 0;
        }
        return $income;
    }
 echo '
';<br> var_dump(getIncome(1, 0, 0));<br>?><div id="MySignature"></div> <div class="clear"></div>
 
                        
                        每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
 
                 
                                
                                 收藏
收藏
                                                                             
                                
                                 收藏
收藏
                                                                             
                                
                                 收藏
收藏
                                                                            Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号