我需要来自单个查询的数组如 (2) 有人可以帮忙吗?
1. Array
(
[0] => Array
(
[crop_id] => 3
[crop_name] => Barley
)
2. Array
(
[0] => Array
(
[Barley] => 3
)
)
最佳答案
不知道查询,但您可以简单地使用array_map()来做到这一点
$array[] = array('crop_id' => 3, 'crop_name' => "Barley");
$result = array_map("myfunction",$array);
print_r($result);
function myfunction($v)
{
$data = [];
$data[$v['crop_name']] = $v['crop_id'];
return $data;
}
关于php - 选择查询以将一列作为mysql中的键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54586530/