how I can get value from input select in ZF3?
$education = $form->get('education');
$education->setValueOptions([
'1' =>'option 1',
'2' => 'option 2',
]);
returns integer value 1,2, not 'option 1' or 'option 2'
Even if I remove index and leave code like below
$education->setValueOptions([
'option 1',
'option 2',
]);
it doesn't work and returns the same as above.
But if I modify code like this
$education->setValueOptions([
'option 1' => 'anything'
'option 2' => 'anything'
]);
it returns correct values as 'option 1' or 'option 2'.
Is is correct, or I'm dooing something wrong?
You're thinking it wrong. For example:
In PHP the value of this array would be
array_value
whilearray_key
would be the key. The logic in zend is the opposite when it is translated to the front-end. In the front end thearray_key
would be the<option>
value while thearray_value
would be the<option>
label.The above code would be translated to the following in the front-end