Grande
Grande

Reputation: 47

How to split the values of each row of a Zend_Form_Element_MultiCheckbox

I have a Zend_Form_Element_MultiCheckbox which has the values:

  1. CSCI 5200 Software [FALL 2013]
  2. CSCI 5200 Design [FALL 2014]

Now I need to split each value before I insert it into to the database. For example, the first value should be split into CSCI, 5200, Software and FALL 2013.

I tried this:

$course = $this->getValue(self::ELEMENT_COURSES);
foreach ($course as $item) {
    foreach($item as $key=>$value) {
        echo $value."\n";
    }

But it does not work.

Upvotes: 0

Views: 92

Answers (2)

ashish
ashish

Reputation: 326

There is still not clarity in your question. But what you wanted is I think, you want to explode those options into the array like,

$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>";

This will result your answer as,

Array (

[0] => Array ( [0] => CSCI [1] => 5200 [2] => Software [3] => FALL 2013 )

[1] => Array ( [0] => CSCI [1] => 5200 [2] => Design [3] => FALL 2014 )

)

I hope this is what you wanted.

Upvotes: 0

doydoy44
doydoy44

Reputation: 5772

I'm not sure I understand, but as there is no answer yet. :)
In your values ​​available (option value) if possible, you should put a separator and then use the side php explode method

Upvotes: 0

Related Questions