Last active
August 30, 2016 10:20
-
-
Save ngugijames/79663ba63e2a4ef720cb832ff2fccdac to your computer and use it in GitHub Desktop.
Ussd with varying questions and responses
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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