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