Thanks to visit codestin.com
Credit goes to github.com

Skip to content

SymfonyStyle ChoiceQuestion - choice to send value or key #40439

Open
@bastien70

Description

@bastien70

Description
Currently, when creating a new Symfony command and using the choice question, like this :

return $io->choice($question, $choices, $default);

It returns the value. But I want the key ! It could be great to give the choice to send key or value with a booleen parameter, like this :

return $io->choice($question, $choices, $default, false);

Example

$choices = [
            0 => 'red',
            1 => 'blue',
            2 => 'orange'
        ];

        return $io->choice('Choose a color', $choices, 0); // Returns the value (red, blur or orange)
        return $io->choice('Choose a color', $choices, 0, false); // Returns the key (0, 1 or 2)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions