在下面的函数get_brand()我想在第一行添加文本: - 选择 - 。 我的想法是使用array_merge。但是我会在所有选项上获得一个空行。添加默认 - 选择 - 选项结果数组在wordpress
我需要做些什么来获取文本: - 选择顶部?
function get_brand() {
global $wpdb;
$brand_array = $GLOBALS['wpdb']->get_results("SELECT brand FROM " . $wpdb->prefix . "automatten GROUP BY brand ORDER BY brand ASC");
$select = array("brand" => '--Select--');
$result = array_merge($select, $brand_array);
return $result;
}
结果是:
阵列([品牌] => - 选择 - [0] => stdClass的对象([品牌] => AIXAM)[1] => stdClass的对象([品牌] =>阿尔法)[2] => stdClass的 对象([品牌] => AMC)[3] => stdClass的对象([品牌] => Artega)
看到结果列表。它被填满,所以不是空的 – Hermants
来自数据库的值是对象,而不是数组。尝试使'$ select'成为一个包含'stdClass'对象的数组,其中'brand'属性的值为'--Select - '。 – StuBez
你能分享你的预期产出吗? –