我有一个像这样的 MySQL 表:
------------
|animal|legs|
------------
| cat 4 |
| chicken 2 |
是否可以在 PHP 中返回一个以 Animals 作为索引名称、legs 作为其值的数组,而无需像 mysqli_fetch_all 那样逐一获取?
$result[cat]=4
$result[chicken]=2.
我试过了
$q = mysqli_fetch_all($q);
$array=array_combine($q2[0], $q2[1]);
但它没有给我我想要的输出。
最佳答案
$dic = $db->getIndCol("animal","SELECT * FROM animals");
关于PHP-MySQL : Returning Query as Array index name and value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17928661/