Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send choice Value instead choice key from Symfony form

I need to send from Symfony form ChoiceType::class

But I don't need choices keys, I need to send choices values.

Is that is possible?

 $form->add('section', ChoiceType::class, array(
                'mapped' => false,
                'choices' => array(
                    1 => 'value1',
                    2 => 'value2'

                ),
          ));

I just want to send value1 if I chose value1,

not key 1 as default.

like image 701
Stevan Tosic Avatar asked Oct 25 '16 17:10

Stevan Tosic


1 Answers

You can use

array_flip ($array)

refer to php docs

like image 191
Aref Ben Lazrek Avatar answered Sep 29 '22 08:09

Aref Ben Lazrek