<?php header("content-type:text/html;charset=utf-8"); //以投资1万元为例 $money = 10000; //指数A $a_mairu = 0.0015; $a_guanli = 0.006; $a_tuoguan = 0.001; $a_xiaoshou = 0; $a_maichu_level = [0,7,30,180,365];//定义卖出时间范围 $a_maichu_arr = array(0.015,0.0075,0.0050,0.0025,0);//定义卖出时间范围的费率 $a_sum_guanli = 0; //指数C $c_mairu = 0; $c_guanli = 0.006; $c_tuoguan = 0.001; $c_xiaoshou = 0.003; $c_maichu_level = [0,7,30]; $c_maichu_arr = array(0.0015,0.0075,0); $c_sum_guanli = 0; for($day = 1;$day<=365;$day++){ echo "投资第".$day."天"; //第一天有申购费率 if($day==1){ echo " 指数A申购费用".$money*$a_mairu."元"; echo " 指数C申购费用".$money*$c_mairu."元"; $a_sum_guanli = $a_sum_guanli + $money*$a_mairu; $c_sum_guanli = $c_sum_guanli + $money*$c_mairu; } //运作费率 $a = round(($a_guanli+$a_tuoguan+$a_xiaoshou)/365*10000,2); $c = round(($c_guanli+$c_tuoguan+$c_xiaoshou)/365*10000,2); $a_sum_guanli = $a_sum_guanli + $a; $c_sum_guanli = $c_sum_guanli + $c; echo " 指数A总运作费用".$a_sum_guanli."元"; echo " 指数C总运作费用".$c_sum_guanli."元"; //赎回费 //赎回A for($j=0;$j<count($a_maichu_level);$j++){ if($j == count($a_maichu_level) - 1){ if($day >= $a_maichu_level[$j]){ //这里通过$j 取得你对应的等级 ,前面我省略了$i对应店铺等级的映射关系 $a_sh_temp = round($a_maichu_arr[$j]*10000,2); echo " 指数A今日赎回费用".$a_sh_temp."元"; } }else{ if($day >= $a_maichu_level[$j] && $day < $a_maichu_level[$j+1]) { //这里通过$j 取得你对应的等级 $a_sh_temp = round($a_maichu_arr[$j]*10000,2); echo " 指数A今日赎回费用".$a_sh_temp."元"; } } } //赎回C for($j=0;$j<count($c_maichu_level);$j++){ if($j == count($c_maichu_level) - 1){ if($day >= $c_maichu_level[$j]){ //这里通过$j 取得你对应的等级 ,前面我省略了$i对应店铺等级的映射关系 $c_sh_temp = round($c_maichu_arr[$j]*10000,2); echo " 指数C今日赎回费用".$c_sh_temp."元"; } }else{ if($day >= $c_maichu_level[$j] && $day < $c_maichu_level[$j+1]) { //这里通过$j 取得你对应的等级 $c_sh_temp = round($c_maichu_arr[$j]*10000,2); echo " 指数C今日赎回费用".$c_sh_temp."元"; } } } echo " 指数A总费用".($a_sum_guanli+$a_sh_temp)."元"; echo " 指数C总费用".($c_sum_guanli+$c_sh_temp)."元"; echo '<br />'; }