我有一个
Zend_Form_Element_MultiCheckbox
,它的值是:
现在我需要在将每个值插入数据库之前对其进行拆分。例如,第一个值应分为 CSCI、5200、Software 和 FALL 2013。
我试过这个:
$course = $this->getValue(self::ELEMENT_COURSES);
foreach ($course as $item) {
foreach($item as $key=>$value) {
echo $value."\n";
}
但是不起作用。
你的问题还是不清楚。但我认为你想要的是,你想将这些选项分解到数组中,就像,
$course = $this->getValue(self::ELEMENT_COURSES);
$finalResult = array();
$counter = 0;
foreach ($course as $value) {
$session = explode("[", $value);
$sessionResult = rtrim($session[1], "]");
$testArray = explode(" ", $session[0]);
unset($testArray[count($testArray) - 1]);
$finalResult[] = array_merge($testArray, array($sessionResult));
}
echo "<pre>";
print_r($finalResult);
echo "</pre>";
这将导致您的答案为,
数组(
[0] => 数组 ( [0] => 中证国际 [1] => 5200 [2] => 软件 [3] => 2013 年秋季 )
[1] => 数组 ( [0] => 中证国际 [1] => 5200 [2] => 设计 [3] => 2014 年秋季 )
)
我希望这是你想要的。