title: Using Form Field to Search Php Associative Array
body: <p><strong>Code:</strong></p>
  
  <pre><code>&lt;?php
  
  echo "&lt;h1&gt;Testing your Trivia&lt;/h1&gt;";
  $ages['1943'] = "Casablanca";
  $ages['1956'] = "Around The World in 80 Days";
  $ages['1970'] = "Patton";
  $ages['1977'] = "Annie Hall";
  $ages['1981'] = "Chariots of Fire";
  $ages['1990'] = "Dances With Wolves";
  $ages['2005'] = "Crash";
  $ages['2006'] = "The Departed";
  
  echo "Give the year below won academy award&lt;br&gt;";
  echo "&lt;Strong&gt;Movie: &lt;/strong&gt; &lt;input type='text' name='' id='' readonly='readonly' /&gt;&lt;br&gt;";
  echo "&lt;Strong&gt;Year it Won the Oscar: &lt;/Strong&gt; &lt;form method='get'&gt;&lt;input type='text' name='year' /&gt;&lt;/form&gt;&lt;input type='submit' /&gt; ";
  
  echo '&lt;pre&gt;';
  foreach( $ages as $key =&gt; $value){
      print_r("Year: $key, Title: $value &lt;br /&gt;");
      }
  echo '&lt;/pre&gt;';
  
  if(isset($_GET['year']))
  {
      if(array_key_exists($_GET['year'], $ages))
      {
           echo "&lt;h2&gt;" . $ages[$_GET['year']] . "&lt;/h2&gt;";
      }
      else
      {
          echo 'Cannot find data';
      }
  }    
  ?&gt;
  </code></pre>
  
  <p>Basically trying to have it setup where I can get the movie input to choose a random title and display it in the input field for "movie", then a user has to guess the year it was made. If their too high, it shows a page saying that, if too low it shows an error as well.</p>
  
  <p>I feel like I need to add in another If/Else for if high or too low. Anyone? </p>
  
  <p>Thanks!!</p>