1

假设你有这个:

while ($record = mysql_fetch_assoc($dbquery)) {
    $arr[] = $record['$columnvalue1'];
}
$arraycount = count($arr);

并且您想要数组中的多个列这是如何完成的?

while ($record = mysql_fetch_assoc($dbquery)) {
    $arr[] = array($record['$columnvalue1'],$record['$columnvalue2']);
}
$arraycount = count($arr);

上述代码错误:

Warning: array_count_values(): Can only count STRING and INTEGER values! 
4

1 回答 1

1

将多个列值添加到数组中

$arr = array();
while ($record = mysql_fetch_array($dbquery)) {
    array_push($arr,$record['$columnvalue1'],$record['$columnvalue2']);
}

求数组的总和

$arraycount = array_sum($arr); //to find the sum of the array
$num = sizeof($arr); //to find the size of the array
于 2012-04-20T07:03:33.803 回答