我运行查询andfetchAll()
$query = "SELECT uid, kill_count FROM users WHERE curmid=:mid AND status='1'";
...
$row = $stmt->fetchAll();
返回此数组:
Array (
[0] => Array ( [uid] => 105 [fcount] => 1 )
[1] => Array ( [uid] => 106 [fcount] => 2 )
[2] => Array ( [uid] => 107 [fcount] => 0 )
[3] => Array ( [uid] => 108 [fcount] => 1 )
[4] => Array ( [uid] => 109 [fcount] => 1 )
)
我有一个循环,基本上可以通过它运行:
$problist = array();
foreach ($row as $key => $value) {
if ($value == 0) {
array_push($problist, $key, $key, $key, $key, $key);
} elseif ($value == 1) {
array_push($problist, $key, $key, $key);
} elseif ($value >= 2) {
$problist[] = $key;
}
}
当然,该循环不起作用,因为它没有在数组中引用适当的值.在此假设下,我正在寻找的输出为:$problist =
array(15) {
[0]=> string(3) "105"
[1]=> string(3) "105"
[2]=> string(3) "105"
[3]=> string(3) "106"
[4]=> string(3) "107"
[5]=> string(3) "107"
[6]=> string(3) "107"
[7]=> string(3) "107"
[8]=> string(3) "107"
[9]=> string(3) "108"
[10]=> string(3) "108"
[11]=> string(3) "108"
[12]=> string(3) "109"
[13]=> string(3) "109"
[14]=> string(3) "109"
}
我已经阅读并修补过,然后再阅读并修补不了要使用哪个php函数来完成这项工作.我已经尝试了end(),reset(),array_shift()等.我很无知,很可能我没有正确使用它们.谢谢您的帮助.
[也许还有更好的方式格式化我的查询?]