2014-01-18 94 views
-3

我試圖找到一種簡單的方式來顯示基於百分比的「是」和「否」。 這只是一個例子,但在vb.net我可以設置一個靜態的,做這樣的事情(70%和30%)根據百分比顯示是或否

 Static iNo As Long, iYes As Long 
     If iNo > iYes * 0.42 Then 
      iYes = iYes + 1 
      Return False 'this is the 70% 
     Else 
      iNo = iNo + 1 
      Return True 'this is the 30% 
     End If 

我究竟能做到什麼這個簡單的使用PHP?

+0

爲什麼不給我們一些PHP代碼?我們愛PHP代碼。是的,我們做! –

+2

你究竟試過了什麼?如果你期望人們把時間和精力投入到他們的答案中,你所能做的至少是把時間和精力放在你的問題上;向我們展示您嘗試過的以及爲什麼它沒有奏效可以幫助我們避免提出您認爲不適合您情況的事情。 – Daedalus

+0

如何設置一個靜態昏暗與PHP? – XK8ER

回答

1
$numVotes = 100; 
$trueVotes = 70; 
$falseVotes = 30; 

function addVote($boolVote){ 

    $numVotes++; 
    if($boolVote) 

     $trueVotes++: 
     return $trueVotes * $numVotes/100; //percent of true votes 
    } 
    else{ 

     $falseVotes++; 
     return $falseVotes * $numVotes/100; //percent of false votes 
} 

$newVote = true; 
$percent = addVote($newVote); 

($newVote)$strVote = "true":$strVote = "false"; 

echo sprintf("The vote is %s and the percent is %01.2f", $strVote, $percent);