ask()
ask(string $question, string $default = '', \Closure $validator = null, integer $times = 3) : string
Ask a question, ask for a limited number of times 若输入了值且验证成功则返回 输入的结果 否则,会连续询问 $times 次, 若仍然错误,退出
Parameters
string | $question | 问题 |
string | $default | 默认值 |
\Closure | $validator | (默认验证输入是否为空)自定义回调验证输入是否符合要求; 验证成功返回true 否则 可返回错误消息 |
integer | $times | Allow input times |
Returns
stringExamples
is an example ```php // no default value Interact::limitedAsk('please entry you age?', null, function($age) { if ($age<1 || $age>100) { Interact::error('Allow the input range is 1-100'); return false; } return true; } ); // has default value Interact::limitedAsk('please entry you age?', 89, function($age) { if ($age<1 || $age>100) { Interact::error('Allow the input range is 1-100'); return false; } return true; } ); ```
** File not found : This **