public function menu($items, $default = null, $title = 'Choose an item')
    {
        if (isset($items[$default]) && strpos($title, '[') === false) {
            $title .= ' [default: ' . $items[$default] . ']';
        }

        $this->line(sprintf('%s: ', $title));

        $i = 1;
        $keys = array();

        foreach ($items as $key => $item) {
            $keys[$i] = $key;
            $this->line(sprintf('  %d. %s', $i, $item));
            $i++;
        }

        $selected = $this->in();

        if ($selected === '') {
            return $default;
        }

        if (isset($keys[$selected])) {
            return $keys[$selected];
        }

        return $selected;
    }
public function menu($items, $default = null, $title = 'Choose an item')
    {
        if (isset($items[$default]) && strpos($title, '[') === false) {
            $title .= ' [default: ' . $items[$default] . ']';
        }

        $this->line(sprintf('%s: ', $title));

        $i = 1;
        $keys = array();

        foreach ($items as $key => $item) {
            $keys[$i] = $key;
            $this->line(sprintf('  %d. %s', $i, $item));
            $i++;
        }

        $selected = $this->in();

        if ($selected === '') {
            return $default;
        }

        if (isset($keys[$selected])) {
            return $keys[$selected];
        }

        return $selected;
    }
public function menu ( $ items , $ default = null , $ title = 'Choose an item' ) { if ( isset ( $ items [ $ default ] ) && strpos ( $ title , '[' ) === false ) { $ title .= ' [default: ' . $ items [ $ default ] . ']' ; } $ this -> line ( sprintf ( '%s: ' , $ title ) ) ; $ i = 1 ; $ keys = array ( ) ; foreach ( $ items as $ key => $ item ) { $ keys [ $ i ] = $ key ; $ this -> line ( sprintf ( '  %d. %s' , $ i , $ item ) ) ; $ i ++ ; } $ selected = $ this -> in ( ) ; if ( $ selected === '' ) { return $ default ; } if ( isset ( $ keys [ $ selected ] ) ) { return $ keys [ $ selected ] ; } return $ selected ; }
Displays a menu where a user can enter a number to choose an option
@param array $items An array like array('key' => 'Label')
@param mixed $default
@param string $title
@return mixed
Displays a menu where a user can enter a number to choose an option