我有這個疑問(這是工作):PHP - 重新人氣指數鍵和值數組中
$filesQuery = "SELECT COUNT(cs_file.iduser) AS newFile, DATE(cs_file.add_date) AS
dateAdded
FROM cs_file
INNER JOIN cs_team_has_user ON cs_team_has_user.iduser = cs_file.iduser
INNER JOIN cs_portal_has_team ON cs_portal_has_team.idteam = cs_team_has_user.idteam
WHERE cs_file.add_date >= DATE(NOW()) - INTERVAL {$range} DAY
AND cs_file.isImage = 0
GROUP BY DATE(cs_file.add_date)
WITH rollup";
查詢給了我這樣的結果:
[0]=>
array(2) {
["newFile"]=>
string(2) "12"
["dateAdded"]=>
string(10) "2016-03-23"
}
[1]=>
array(2) {
["newFile"]=>
string(1) "2"
["dateAdded"]=>
string(10) "2016-04-01"
}
[2]=>
array(2) {
["newFile"]=>
string(2) "10"
["dateAdded"]=>
string(10) "2016-04-22"
}....
我需要怎麼做是製作dateadded一個關鍵和newFile(計數)一個值。像這樣:
[
'2016-03-23' => '12',
'2016-04-01' => '2',
'2016-04-22' => '10'
]
這是可能的查詢嗎?或者有一些更有效的方法,然後使用foreach循環?
它可以很容易使用[array_column()](http://www.php.net/manual/en/function.array-column.php)來完成:'$結果= array_column($結果, 'newFile','dateAdded');' –