Skip to content

Instantly share code, notes, and snippets.

@ngugijames
Last active August 30, 2016 10:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ngugijames/79663ba63e2a4ef720cb832ff2fccdac to your computer and use it in GitHub Desktop.
Save ngugijames/79663ba63e2a4ef720cb832ff2fccdac to your computer and use it in GitHub Desktop.
Ussd with varying questions and responses
<?php
/**
* Collaborated with http://github.com/pittgikera
*/
$text = $_GET['text'];
//$questions = "How was is it? # Was it enjoyable?# Did you have fun? # Will you come back?";
$questions = "";
//we use array filter to remove indices whose values are empty
$questionsArray = array_filter(explode('#', $questions));
$responseArray = array_filter(explode('*', $text));
if (count($questionsArray) < 1) {
echo "We don't have questions for you today!";
} else {
$currentQuestion = null;
for ($i = 0; $i < count($questionsArray); $i++) {
if (isset($responseArray[$i + 1])) {
//question has been answered
} else {
//question not answered
$currentQuestion = $i;
break;
}
}
if (is_null($currentQuestion)) {
//if the current question is null, they've answered everything
echo "You've answered everything";
} else {
//show that question now!
echo $questionsArray[$currentQuestion];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment