如何在表单中添加动态单选按钮?

How to add dynamic radio buttons in form?

我需要帮助。如何在现有表单中添加单选按钮? 我尝试这样做:

$metodadeplata = array('ramburs','ordindeplata');

   foreach($metodedeplata as $metoda){

        $radio = new Element\Radio('metodedeplata');
        $radio->setValue($metoda);
        $checkoutform->add($radio);

    }

,但它只取最后一个值。 $checkoutform 是一个已经声明的表格。

根据 the doc,无线电元素不是这样工作的:

$radio = new Element\Radio('metodedeplata');
$radio->setLabel('Label for metodedeplata');
$radio->setValueOptions([
    '0' => 'ramburs',
    '1' => 'ordindeplata',
]);

$checkoutform->add($radio);