我有下面的代码,需要25秒才能在屏幕上显示数据。
关于如何用isset代替in_array,你有什么想法吗?
我认为这可以快得多!
if (!$matches[0]['match_id']) $matches = array();
for ($i=0; $i<count($matches); $i++) {
if (in_array($matches[$i]['match_id'],$validMatches)) {
$match_stats = $db->get_by_fields('player_match_stats', array('match_id'=>$matches[$i]['match_id'], 'player_id'=>$pid));
if($match_stats['points']!='') $ret[0]++;
$ret[1] = $ret[1] + $match_stats['points'];
$ret[2] = $ret[2] + $match_stats['threepoints'];
}
}
if ($ret[0] != 0) {
$ret[3] = $ret[1] / $ret[0];
$ret[3] = number_format($ret[3], 1);
}
return $ret;发布于 2020-05-31 11:53:37
以下是我的几点心得:
for循环中使用计数。它在每次迭代时都会计算长度。如果您有数组,请改用foreach。array_intersect从matches数组中检索所有有效的匹配项。WHERE id IN (12,13,15,16,...,77)一次性检索数据库中的所有记录。然后迭代您的结果。https://stackoverflow.com/questions/62110519
复制相似问题