1

I am using $io->choice() to offer some selections in a RoboFile setup. It uses symfony's $io class.

The options that are given are starting at 0, not 1. Is it possible to offer options starting from 1 instead of 0 or maybe add a "non-selectable option" for the first item? (0 is quite far away from 1,2,3 on the keyboard).

Sample Image

Patrick
  • 691
  • 8
  • 30
  • Possible duplicate of [how to change the array key to start from 1 instead of 0](https://stackoverflow.com/questions/5374202/how-to-change-the-array-key-to-start-from-1-instead-of-0) – EternalHour Mar 08 '19 at 19:16
  • @EternalHour it was unclear to me that the function changes a one-dimensional array into an indexed one. I think my question is more related to the io() function of Symfony. I know how to change indexes - if I know they are there ;) – Patrick Mar 11 '19 at 12:52

1 Answers1

2

The array you submit to choice() needs to start at 1.

$choices = [];
$choices[1] = 'hdtours';
$choices[2] = 'hdtravel';
$choices[3] = 'boutiqueyachting';

$io->choice('Which installation?', $choices);
  • Thanks. I did not know that this could be done by array keys. Opens up lots of opportunities :) – Patrick Mar 11 '19 at 12:50