src/Console/Component/Prompter.php
public function choose(string $prompt, array $choices)
    {
        echo "$prompt: \n";

        $choicesMap = [];

        $i = 0;
        if (Arrays::isAssoc($choices)) {
            foreach ($choices as $choice => $value) {
                $choicesMap[++$i] = $value;
                echo "\t$i: " . $choice . ' => ' . $value . "\n";
            }
        } else {
            //is sequential
            foreach ($choices as $choice) {
                $choicesMap[++$i] = $choice;
                echo "\t$i: $choice\n";
            }
        }

        if ($this->style) {
            echo $this->formatter->getStartMark($this->style);
        }

        $completionItems = array_keys($choicesMap);
        $choosePrompt = "Please Choose 1-$i > ";

        if (ReadlineConsole::isAvailable()) {
            readline_completion_function(function () use ($completionItems) {
                return $completionItems;
            });
        }

        while (true) {
            $answer = (int) trim($this->console->readLine($choosePrompt));

            if (isset($choicesMap[$answer])) {
                if ($this->style) {
                    echo $this->formatter->getClearMark();
                }

                return $choicesMap[$answer];
            }
        }
    }
public function choose(string $prompt, array $choices)
    {
        echo "$prompt: \n";

        $choicesMap = [];

        $i = 0;
        if (Arrays::isAssoc($choices)) {
            foreach ($choices as $choice => $value) {
                $choicesMap[++$i] = $value;
                echo "\t$i: " . $choice . ' => ' . $value . "\n";
            }
        } else {
            //is sequential
            foreach ($choices as $choice) {
                $choicesMap[++$i] = $choice;
                echo "\t$i: $choice\n";
            }
        }

        if ($this->style) {
            echo $this->formatter->getStartMark($this->style);
        }

        $completionItems = array_keys($choicesMap);
        $choosePrompt = "Please Choose 1-$i > ";

        if (ReadlineConsole::isAvailable()) {
            readline_completion_function(function () use ($completionItems) {
                return $completionItems;
            });
        }

        while (true) {
            $answer = (int) trim($this->console->readLine($choosePrompt));

            if (isset($choicesMap[$answer])) {
                if ($this->style) {
                    echo $this->formatter->getClearMark();
                }

                return $choicesMap[$answer];
            }
        }
    }
public function choose ( string $ prompt , array $ choices ) { echo "$prompt: \n" ; $ choicesMap = [ ] ; $ i = 0 ; if ( Arrays :: isAssoc ( $ choices ) ) { foreach ( $ choices as $ choice => $ value ) { $ choicesMap [ ++ $ i ] = $ value ; echo "\t$i: " . $ choice . ' => ' . $ value . "\n" ; } } else { //is sequential foreach ( $ choices as $ choice ) { $ choicesMap [ ++ $ i ] = $ choice ; echo "\t$i: $choice\n" ; } } if ( $ this -> style ) { echo $ this -> formatter -> getStartMark ( $ this -> style ) ; } $ completionItems = array_keys ( $ choicesMap ) ; $ choosePrompt = "Please Choose 1-$i > " ; if ( ReadlineConsole :: isAvailable ( ) ) { readline_completion_function ( function ( ) use ( $ completionItems ) { return $ completionItems ; } ) ; } while ( true ) { $ answer = ( int ) trim ( $ this -> console -> readLine ( $ choosePrompt ) ) ; if ( isset ( $ choicesMap [ $ answer ] ) ) { if ( $ this -> style ) { echo $ this -> formatter -> getClearMark ( ) ; } return $ choicesMap [ $ answer ] ; } } }
Provide a simple console menu for choices,
which gives values an index number for user to choose items.

@code

$val = $app->choose('Your versions' , array(
'php-5.4.0' => '5.4.0',
'php-5.4.1' => '5.4.1',
'system' => '5.3.0',
));
var_dump($val);

@code

@param  string $prompt Prompt message
@param  array  $choices

@return mixed  value
Provide a simple console menu for choices which gives values an index number for user to choose items .