我的這些值在array
= Array ([0] => 3 [1] => 2 [2] => 10 [3] => 5)
PHP:從陣列獲取的每個值,並計算
我如何從array
分別獲得每個值,並執行下面的計算?
$j=$q*100/$ytot;
而且這是我到目前爲止已經試過,其心不是給正確的值:
$resul=mysql_query("select * from post_bet where bet_id = '$id'")or die(mysql_error());
if(mysql_num_rows($resul)>0)
{
while($row=mysql_fetch_assoc($resul))
{
$y_uid=$row['yes_userid'];
$y_uamt=$row['yes_useramount'];
$n_uid=$row['no_userid'];
$n_uamt=$row['no_useramount'];
$ytot=$row['yes_total'];
$ntot=$row['no_total'];
$hhh=explode(',',$row['yes_useramount']);
$q = print_r($hhh);
echo $j=$q*100/$ytot;
}
}
你想在這裏做什麼?你想要爲每個數組值執行操作還是要將操作附加到單個變量$ j – Jenz
Yessir!我確實想要計算每個值。請忽略我的錯誤。 – MetaldroiD
您需要指定您的計算含義。什麼是'$ j','$ q'和'$ ytot'? –