使用 MySQLi 选择行数组


Selecting an array of rows using MySQLi

我正在尝试从不同行号的数组中返回结果。现在,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";
}

while 循环中使用如下数组:

$interestValue = 0;
foreach ( $currentUsers as $i ) {
    $interestValue = $interestValue + (int) $row[$i];
}
echo $interestValue;