我想在 drupal 表单 API 中添加 key(type_id) 和 value(type_description) 来选择
$result_x->product_types->RPMProductType 是来自数据库的数组结果:- array(4) { [0]=> object(stdClass)#18 (2) { ["type_description"]=> string(10) "Calendered" [ "type_id"]=> int(1) } [1]=> object(stdClass)#19 (2) { ["type_description"]=> string(8) "Extruded" ["type_id"]=> int(2 ) } [2]=> object(stdClass)#20 (2) { ["type_description"]=> string(6) "Molded" ["type_id"]=> int(3) } [3]=> object( stdClass)#21 (2) { ["type_description"]=> string(5) "其他" ["type_id"]=> int(4) } }
foreach ($result_x->product_types->RPMProductType as $data) { $form['manufacturer_add_new_sales']['product_type'] = array( '#type' => '选择', '#title' => t('产品类型'), '#options'=>array($data->type_id=>$data->type_description), ); }
什么时候这样做我只得到最后一个值,即其他。如何正确循环绑定 Select 以显示所有数组 Key - Values。
先感谢您。