我使用填充的一個有預渲染濾波器WordPress的重力形式。手冊PHP數組只返回最後一個值
我按照他們的正常documentation我使用foreach循環,其每一次工作動態填充$項目[]。
但此時我不是動態正在爲$項[]數組,我手動輸入每個值到一個數組一個PHP foreach循環。
請參考下面...
add_filter("gform_pre_render", "populate_dropdown_bike_make");
add_filter("gform_admin_pre_render", "populate_dropdown_bike_make");
function populate_dropdown_bike_make($form){
if($form["id"] != 4)
return $form;
$items = array();
$items[] = array(
"text" => "", "value" => null,
"text" => "YAMASAKI", "value" => "YAMASAKI",
"text" => "YAMOTO", "value" => "YAMOTO",
"text" => "YEZDI", "value" => "YEZDI",
"text" => "YIBEN", "value" => "YIBEN",
"text" => "YIYING", "value" => "YIYING",
"text" => "YONGKANG", "value" => "YONGKANG",
"text" => "YONGWANG", "value" => "YONGWANG",
"text" => "ZEBRETTA", "value" => "ZEBRETTA",
"text" => "ZENNCO", "value" => "ZENNCO",
"text" => "ZEPII", "value" => "ZEPII",
"text" => "ZERO-MOTORCYCLES", "value" => "ZERO-MOTORCYCLES",
"text" => "ZEV", "value" => "ZEV",
"text" => "ZHEJIANG", "value" => "ZHEJIANG",
"text" => "ZHENHUA", "value" => "ZHENHUA",
"text" => "ZHIXI", "value" => "ZHIXI",
"text" => "ZHONGYU", "value" => "ZHONGYU",
"text" => "ZING", "value" => "ZING",
"text" => "ZIPPI", "value" => "ZIPPI",
"text" => "ZIPSTAR", "value" => "ZIPSTAR",
"text" => "ZONGSHEN", "value" => "ZONGSHEN",
"text" => "ZONTES", "value" => "ZONTES",
"text" => "ZUNDAPP", "value" => "ZUNDAPP"
);
foreach($form["fields"] as &$field)
if($field["id"] == 45){
$field["choices"] = $items;
}
return $form;
}
現在有了這個問題它只是返回在下拉列表中最後一個選項春達普。
任何人都可以看到爲什麼會發生這種情況嗎?
謝謝
您的陣列只有兩個條目,一個是文本鍵,另一個是鍵值。您會在每行上覆蓋該值,因此最後,ZUNDAPP是其中唯一的值。 – andrewsi