title: Building an expert system/decision based in PHP
body: <p>The problem I am trying to solve is I have 16 different animals and I need to write a PHP script that asks the user 4 yes/no questions and each question narrows down the available animals until eventually the answer is displayed. This means that the next question will depend on what the user answered in the previous question. Do you have any idea how I can do this without using loads of if else statements.</p>
  
  <p>Below is what I have done so far, not finished but if I carry on using if statements I will just end up with too much, there must be a better way to do it. Someone suggested to me using arrays within arrays, but that doesn't help me. Any help would be much appreciated.</p>
  
  <pre><code>&lt;?php
  session_set_cookie_params(2592000);
  session_start();
  ?&gt;
  
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Creature Guessing Game&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h1&gt;Creature Guessing Game&lt;/h1&gt;
  &lt;p&gt; Welcome to the creature guessing game! &lt;/p&gt;
  &lt;p&gt;Click the button 
  
  below to start or restart the game &lt;/p&gt;
  
  &lt;form method="post" action="Creatures.php"&gt;
  &lt;input type='submit' name='start' value='Start Game' /&gt;
  &lt;/form&gt;
   &lt;?php
  //If form not submitted, display form.
  if (!isset($_POST['start'])){
  ?&gt;
  &lt;?php
  } //If form is submitted, process input
  
  else{ //Question 1
  echo "&lt;p&gt;Does the creature live mainly on the land?&lt;/p&gt;";
  echo "&lt;form method='post' action='Creatures.php'&gt;
  &lt;input type='submit' name='yes1' value='Yes' /&gt;
  &lt;input type='submit' name='no1' value='No' /&gt;
  &lt;/form&gt;";
  }
  if ($_POST['yes1']){ //Q1 - Yes
  echo "&lt;p&gt;Does the creature have wings?&lt;/p&gt;";
  echo "&lt;form method='post' action='Creatures.php'&gt;
  &lt;input type='submit' name='yes2' value='Yes' /&gt;
  &lt;input type='submit' name='no2' value='No' /&gt;
  &lt;/form&gt;";
  }
  elseif($_POST['no1']){ //Q1 - No
  echo "&lt;p&gt;Does the creature live in the water?&lt;/p&gt;";
  echo "&lt;form method='post' action='Creatures.php'&gt;
  &lt;input type='submit' name='yes3' value='Yes' /&gt;
  &lt;input type='submit' name='no3' value='No' /&gt;
  &lt;/form&gt;";
  }
  if ($_POST['yes2']){ //Q1 - Yes and Q2 - Yes
  echo "&lt;p&gt;Can the creature fly?&lt;/p&gt;";
  echo "&lt;form method='post' action='Creatures.php'&gt;
  &lt;input type='submit' name='yes4' value='Yes' /&gt;
  &lt;input type='submit' name='no4' value='No' /&gt;
  &lt;/form&gt;";
  }
  elseif($_POST['no2']){ //Q1 - Yes and Q2 - No
  echo "&lt;p&gt;Is the creature an insect?&lt;/p&gt;";
  echo "&lt;form method='post' action='Creatures.php'&gt;
  &lt;input type='submit' name='yes5' value='Yes' /&gt;
  &lt;input type='submit' name='no5' value='No' /&gt;
  &lt;/form&gt;";
  }
  if ($_POST['yes3']){ //Q1 - No and Q2 - Yes
  echo "&lt;p&gt;Is the creature a reptile?&lt;/p&gt;";
  echo "&lt;form method='post' action='Creatures.php'&gt;
  &lt;input type='submit' name='yes6' value='Yes' /&gt;
  &lt;input type='submit' name='no6' value='No' /&gt;
  &lt;/form&gt;";
  }
  if ($_POST['no3']){ //Q1 - No and Q2 - No
  echo "&lt;p&gt;Does the creature have feathers?&lt;/p&gt;";
  echo "&lt;form method='post' action='Creatures.php'&gt;
  &lt;input type='submit' name='yes7' value='Yes' /&gt;
  &lt;input type='submit' name='no7' value='No' /&gt;
  &lt;/form&gt;";
  }
  if ($_POST['yes4']){ //Q1 - Yes and Q2 - Yes and Q3 - Yes
  echo "&lt;p&gt;Is the creature your thinking of white?&lt;/p&gt;";
  echo "&lt;form method='post' action='Creatures.php'&gt;
  &lt;input type='submit' name='yes8' value='Yes' /&gt;
  &lt;input type='submit' name='no8' value='No' /&gt;
  &lt;/form&gt;";
  }
  if ($_POST['yes8']){ //Answer 1: Q1 - Yes and Q2 - Yes and Q3 - Yes and Q4 - Yes 
  echo "&lt;p&gt;Its a goose!&lt;/p&gt;";
  }
  if ($_POST['no8']){ //Answer 2: Q1 - Yes and Q2 - Yes and Q3 - Yes and Q4 - No
  echo "&lt;p&gt;Its a hawk!&lt;/p&gt;";
  }
  ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>