【发布时间】:2014-09-10 22:42:13
【问题描述】:
我有以下 PHP/MYSQL 查询:
$sql = SELECT type, count(*) AS total FROM stats GROUP BY type
$this->sql = $sql;
function numObjects() {
$stats = $this->conn->query($this->sql);
while($stat_type = $stats->fetch_assoc()){
$category[] = $stat_type;
}
return $category;
}
这是一个简单的查询,但我不知道如何以我想要的方式检索数据,因为它返回的是一个多维数组。
array(2) {
[0]=> array(2) {
["type"]=> string(4) "page"
["total"]=> string(1) "1"
}
[1]=> array(2) {
["type"]=> string(8) "category"
["total"]=> string(1) "1"
}
}
我要做的是将每个数组中的值转换为键 => 值对。像这样:
["page"]=> "1"
["category"]=> "1"
我已经能够将其转换为一维数组,但格式不正确。
【问题讨论】:
标签: php mysql arrays multidimensional-array