我被困在计算交易总数中我没有得到什么公式使用。任何人都可以帮助我,并给我逻辑或公式? see the image to know what i want
答案 0 :(得分:1)
从问题中你不需要理解你需要什么,但根据图像,这就是你想要的:
$sellbuy = array("b","s","b","b","b","s","b","s","s");
$amount = array("10","10","1","1","1","3","5","2","3");
$trades=0;
$i=0;
$tamount=0;
$a=0;
foreach($sellbuy as $saction){
echo $i.") ".getTotalTrades($saction,$amount[$i],$trades,$tamount)."<br />";
$i++;
}
function getTotalTrades($faction,$famount,&$trades,&$tamount){
if($faction=="s"){
if($trades==0 || $trades==1){
$toreturn = "1, in amount of: ".$famount."<br />";
}else{
$toreturn = $trades.", in amounts of: ".$tamount."<br />";
}
$trades=0;
$tamount = 0;
return $toreturn;
}else{ //the user is buying
$trades++;
$tamount = $famount+$tamount;
return "buy only";
}
}
当然,您可以根据需要进行更改。
祝你好运!