bets=array( 'cuotas'=>array(), 'total_apuestas'=>0, 'apuesta'=>0, 'total'=>0, 'ganancias'=>0, 'porcentaje'=>0 ); } function addBets($bets=array()){ if(is_array($bets) && count($bets)>0){ foreach ($bets as $k=>$v){ $this->addBet($v); } } } function addBet($bet=0, $ps=0){ if($bet>0){ $div=1/$bet; $this->bet+=$div; $this->cache[]="1/{$bet}"; $pos=($ps>0?$ps:count($this->bets['cuotas'])+1); $this->bets['cuotas'][$pos]=array( 'cuota'=>(float)$bet, 'division'=>$div, 'porcentaje'=>0, 'apuesta'=>0 ); } } function number($num=0){ return (float)number_format($num,2,'.',','); } function check(){ foreach ($this->bets['cuotas'] as $k=>$elems){ $res=(($elems['division']*100)/$this->bet); $this->bets['cuotas'][$k]['porcentaje']=round($res,2); $this->bets['cuotas'][$k]['apuesta']=round($res*($this->apuesta/100),2); } $this->bet=(((100/$this->bet)-100)/100); $this->bets['total_apuestas']=count($this->bets['cuotas']); $this->bets['apuesta']=$this->apuesta; $this->bets['total']=($this->apuesta*$this->bet) ; $this->bets['ganancias']=$this->number($this->apuesta*$this->bet); $this->bets['porcentaje']=round($this->bet*100,2); $this->surebet=($this->bets['ganancias']>0)?true:false; } function print_bet(){ if($this->debug){ echo "
";
			echo "".(implode("+",$this->cache))."=".($this->bet)."
"; var_dump($this->bets); echo "
"; } $haycuotas=($this->bets['total_apuestas']>0?true:false); for($i=1; $i<=$this->maxbets; $i++){ if(!$this->bets['cuotas'][$i]){ $this->bets['cuotas'][$i]=array('cuota'=>0,'porcentaje'=>0,'apuesta'=>0); } } echo '
'; echo ""; echo ""; echo ""; echo ""; foreach ($this->bets['cuotas'] as $k=>$elems){ echo ""; echo ""; echo "\n"; echo "\n"; echo "\n"; if($k==1){ echo "\n"; echo "\n"; } echo ""; } echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "
Numero de opciones: "; echo ""; echo "
Opción {$k}:{$elems['porcentaje']}%{$elems['apuesta']}€{$this->bets['ganancias']}€{$this->bets['porcentaje']}%
Poner aquí la cantidad total para apostar >>>>>
"; echo "
"; } } $calc=new calc_bets(); if($_GET['maxbets'] && intval($_GET['maxbets'])>=2){ $calc->maxbets=intval($_GET['maxbets']); } if($_POST && count($_POST['bet'])>0){ $calc->apuesta=(intval($_POST['apuesta'])>0?intval($_POST['apuesta']):10); $calc->addBets($_POST['bet']); $calc->check(); } ?> print_bet(); ?>