mysql表:
+-------------------+----------------+
| config_name | config_value |
+-------------------+----------------+
| allow_autologin | 1 |
| allow_md5 | 0 |
+-------------------+----------------+
当前的PHP代码:
$sth = mysql_query("SELECT ...");
$rows = array();
while($r = mysql_fetch_assoc($sth)) {
$rows[] = $r;
}
print_r($rows);
目前的结果:
Array
(
[0] => Array
(
[config_name] => allow_autologin
[config_value] => 1
)
[1] => Array
(
[config_name] => allow_md5
[config_value] => 0
)
)
我想得到这样的结果:
Array(allow_autologin => 1, allow_md5 => 0)
答案 0 :(得分:5)
只需添加到您的搜索结果中:
$sth = mysql_query("SELECT ...");
$rows = array();
while($r = mysql_fetch_assoc($sth)) {
$rows[$r['config_name']] = $r['config_value'];
}
print_r($rows);
答案 1 :(得分:4)
while($r = mysql_fetch_assoc($sth)) {
$rows[] = array($r['config_name'] => $r['config_value']);
}
答案 2 :(得分:1)
$sth = mysql_query("SELECT ...");
$rows = array();
while($r = mysql_fetch_assoc($sth)) {
$rows[$r['config_name']] = $r['config_value'];
}
print_r($rows);