我试图从不同行号的数组中返回结果。现在手动输入mysqli查询中的每个行号。您如何用currentUsers
数组的值替换这些值?
$currentUsers = array('1', '3', '7', '10');
while ($row = mysqli_fetch_array ($query))
{
$interestValue = ((int) "$row[1]") +
((int) "$row[3]") +
((int) "$row[7]") +
((int) "$row[10]");
echo "$interestValue";
}
答案 0 :(得分:0)
在while
循环内部使用如下数组:
$interestValue = 0;
foreach ( $currentUsers as $i ) {
$interestValue = $interestValue + (int) $row[$i];
}
echo $interestValue;