If you want to run php in the console has a simple solution that works from version 4 of php until today (my version is 7.2) that is the readline.
Unfortunately he needs the user to press enter after typing
$c = readline("Enter y for yes and n for no and press enter to confirm\n");
$c = strtolower($c);
if ($c == 'y' || $c == 'yes' ) {
echo 'You chose yes' . PHP_EOL;
} else {
echo 'You chose no [' . $c . ']' . PHP_EOL;
}
echo 'exiting program...' . PHP_EOL;
You can also use the stream_get_line function