Php 向Zend MultiCheckbox动态添加键和值

Php 向Zend MultiCheckbox动态添加键和值,php,zend-framework,Php,Zend Framework,我从这样的数据库中检索了courseList和courseId foreach(课程作为$item){ $checkBoxText=''; $checkBoxText.=$item['courseRubric'].-“$item['courseNumber'.]”.$item['CourseTile'.[“$item['Sembert'.]”.“$item['year'.]” 现在,我想将这些数组项添加到Zend_MultiCheckbox, foreach($this->courseId作为$

我从这样的数据库中检索了courseList和courseId foreach(课程作为$item){ $checkBoxText=''; $checkBoxText.=$item['courseRubric'].-“$item['courseNumber'.]”.$item['CourseTile'.[“$item['Sembert'.]”.“$item['year'.]”

现在,我想将这些数组项添加到Zend_MultiCheckbox, foreach($this->courseId作为$key=>$value){ $courseId[$value]=$value; } foreach($this->courseList as$key=>value){

这个逻辑不起作用。有人能告诉我怎么做吗 课程

谢谢

您有两种解决方案:

1:

2:

我认为第二个更好。

祝你好运

           $this->courseList[] = $checkBoxText;

           $checkboxId = '';
           $checkboxId .= $item['id'];
           $this->courseId[] = $checkboxId;

        }
         $element->addMultiOptions(array(
            $courseId[$key] => $value

         ));
    }
foreach ($this->courseList as $key => $value) {
     $element->addMultiOption("$courseId[$key]", "$value");
}
$opions = array();
foreach ($this->courseList as $key => $value) {
   $options[$courseId[$key]] = $value;
}
$element->addMultiOptions($options);