【发布时间】:2020-07-17 16:56:31
【问题描述】:
我有一个数组:
$location= $wpdb->get_results("
SELECT
town, county, country
FROM
" . $wpdb->prefix . "table WHERE ID = " . $ID);
这只会返回一行,因为 ID 是唯一的。
我需要将这些数据放入一个数组中,使其看起来像:
array("Base" => $basetype,
"Fields" => array("town"=>"Birmingham", "county"=>"West Midlands", "country"=>"UK"))
如果我对这一行进行硬编码,API 可以工作,但如果我尝试使用:
array("Base" => $basetype,
"Fields" => $location
我似乎添加了一个我不想要的额外数组:
Array ( [Base] => test [Fields] => Array ( [0] => Array ( [Town] => Birmingham [County] => West Midlands [Country] => UK
如何避免这个额外的数组 (=> Array ( [0])?这是 WordPress 特有的吗?我已经尝试更改get_results的格式,但无济于事。
【问题讨论】:
-
您做错了什么,不是添加该数组的那一行,如果那不是您使用的代码,请发布您正在使用的确切代码