Skip to content

Instantly share code, notes, and snippets.

@vielhuber
vielhuber / index.php
Created January 31, 2017 23:11
PHP-cli ask user for command line input #php
<?php
function ask($question, $answers = null) {
echo $question.' ';
$handle = fopen("php://stdin","r");
$answer = fgets($handle);
fclose($handle);
$answer = trim($answer);
if($answers != null) {
if( !in_array($answer,$answers) ) {
return ask($question, $answers);