I'm trying to write a simple PHP script that acts like a set of flash cards. I want to have the script prompt me (via a command prompt) with a question and then once I'm ready then I hit Enter and it shows me the answer. Then I hit Enter and it shows me the next question and so on.
I've written the below script but when I press Enter the first time it goes all the way through the array and then finishes all at once. I want to have it pause for input in between each question and answer.
$questionsandanswers = array(
"What is 1 plus 1?",
"2",
"What is 2 plus 2?",
"4",
);
foreach ($questionsandanswers as $qa) {
echo $qa . "\n";
$handle = fopen ("php://stdin","r");
$line = fgets($handle);
if ($line) {
echo $qa . "\n";
fclose($handle);
}
}