title: Checking if function already ran
body: <p>I'm trying to see if I can make this function check to see if it's been ran already when it's called twice. Basically it shows a description of the state first, calls the display_form function again, brings up a form at the bottom for the user to choose a perticular city and I want to show a description of the city selected. I am pretty confused right now with it.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>    &lt;body&gt;
  
  
          &lt;h1&gt;State and City Description&lt;/h1&gt;
          &lt;?php
  
              function display_form()
              {
                  $stateArray = array('Pennsylvania'=&gt;'Pennsylvania', 'California'=&gt;'California', 'Florida'=&gt;'Florida', 'Colorado'=&gt;'Colorado', 'Texas'=&gt;'Texas');
                  $cityPA_Array = array('a'=&gt;'Philadelphia', 'b'=&gt;'Harrisburg', 'c'=&gt;'Pittsburgh');
                  $cityCA_Array = array('a'=&gt;'San Francisco', 'b'=&gt;'Los Angeles', 'c'=&gt;'San Diego');
                  $cityFL_Array = array('a'=&gt;'Miami', 'b'=&gt;'Naples', 'c'=&gt;'Orlando');
                  $cityCO_Array = array('a'=&gt;'Boulder', 'b'=&gt;'Auora', 'c'=&gt;'Colorado Springs');
                  $cityTX_Array = array('a'=&gt;'Houston', 'b'=&gt;'Dallas', 'c'=&gt;'Austin');
  
                  if($var == 0) {
                  $form = '&lt;form action="testsad.php" method="post"&gt;';
                  $form .= '&lt;table&gt;';
                  $form .= '&lt;tr&gt;&lt;td style="width:150px;"&gt;Name:&lt;/td&gt;'.
                           '&lt;td style="width:150px;"&gt;&lt;input type="text" name="formName" /&gt;&lt;/td&gt;&lt;/tr&gt;';
                  $form .= '&lt;tr&gt;&lt;td&gt;Select a state to visit:&lt;/td&gt;&lt;td&gt;
                            &lt;select name=\'stateName\'&gt;';
  
                  foreach ($stateArray as $stateAbbrev =&gt; $stateName) {
                  $form .= '&lt;option value="'.$stateAbbrev.'"&gt;'.$stateName.'&lt;/option&gt;';
                           }//end foreach loop
                  $form .= '&lt;tr&gt;&lt;td style="text-align:center;"&gt;&lt;input type="submit" value="Submit" /&gt;&lt;/td&gt;&lt;/tr&gt;';
  
                  $form .= '&lt;/select&gt;
                            &lt;/td&gt;&lt;/tr&gt;
                            &lt;/form&gt;&lt;p&gt;&lt;/p&gt;';
                  $var = 1;
                  }//end if statement
                  elseif($GLOBALS['first'] == 1) {
  
                       if($stateName =='Pennsylvania') {
                          $form = '&lt;form action="testsad.php" method="post"&gt;';
                          $form .= '&lt;table&gt;';
                          $form .= '&lt;tr&gt;&lt;td&gt;Select a city to visit:&lt;/td&gt;&lt;td&gt;
                                   &lt;select name=\'cityName\'&gt;';
  
                                  foreach ($cityPA_Array as $cityChoice =&gt; $cityName) {
                          $form .= '&lt;option value="'.$cityChoice.'"&gt;'.$cityName.'&lt;/option&gt;';
                                  }//end foreach loop
                          $form .= '&lt;tr&gt;&lt;td style="text-align:center;"&gt;&lt;input type="submit" value="Submit" /&gt;&lt;/td&gt;&lt;/tr&gt;';
  
                          $form .= '&lt;/select&gt;
                                   &lt;/td&gt;&lt;/tr&gt;
                                   &lt;/form&gt;&lt;p&gt;&lt;/p&gt;';
                       }//end if
                          elseif($stateName =='California') {
                          $form = '&lt;form action="testsad.php" method="post"&gt;';
                          $form .= '&lt;table&gt;';
                          $form .= '&lt;tr&gt;&lt;td&gt;Select a city to visit:&lt;/td&gt;&lt;td&gt;
                                   &lt;select name=\'cityName\'&gt;';
  
                                  foreach ($cityCA_Array as $cityChoice =&gt; $cityName) {
                          $form .= '&lt;option value="'.$cityChoice.'"&gt;'.$cityName.'&lt;/option&gt;';
                                  }//end foreach loop
                          $form .= '&lt;tr&gt;&lt;td style="text-align:center;"&gt;&lt;input type="submit" value="Submit" /&gt;&lt;/td&gt;&lt;/tr&gt;';
  
                          $form .= '&lt;/select&gt;
                                   &lt;/td&gt;&lt;/tr&gt;
                                   &lt;/form&gt;&lt;p&gt;&lt;/p&gt;';
                       }//end elseif                         
                          elseif($stateName =='Florida') {
                          $form = '&lt;form action="testsad.php" method="post"&gt;';
                          $form .= '&lt;table&gt;';
                          $form .= '&lt;tr&gt;&lt;td&gt;Select a city to visit:&lt;/td&gt;&lt;td&gt;
                                   &lt;select name=\'cityName\'&gt;';
  
                                  foreach ($cityFL_Array as $cityChoice =&gt; $cityName) {
                          $form .= '&lt;option value="'.$cityChoice.'"&gt;'.$cityName.'&lt;/option&gt;';
                                  }//end foreach loop
                          $form .= '&lt;tr&gt;&lt;td style="text-align:center;"&gt;&lt;input type="submit" value="Submit" /&gt;&lt;/td&gt;&lt;/tr&gt;';
  
                          $form .= '&lt;/select&gt;
                                   &lt;/td&gt;&lt;/tr&gt;
                                   &lt;/form&gt;&lt;p&gt;&lt;/p&gt;';
                       }//end elseif                            
                          elseif($stateName =='Texas') {
                          $form = '&lt;form action="testsad.php" method="post"&gt;';
                          $form .= '&lt;table&gt;';
                          $form .= '&lt;tr&gt;&lt;td&gt;Select a city to visit:&lt;/td&gt;&lt;td&gt;
                                   &lt;select name=\'cityName\'&gt;';
  
                                  foreach ($cityTX_Array as $cityChoice =&gt; $cityName) {
                          $form .= '&lt;option value="'.$cityChoice.'"&gt;'.$cityName.'&lt;/option&gt;';
                                  }//end foreach loop
                          $form .= '&lt;tr&gt;&lt;td style="text-align:center;"&gt;&lt;input type="submit" value="Submit" /&gt;&lt;/td&gt;&lt;/tr&gt;';
  
                          $form .= '&lt;/select&gt;
                                   &lt;/td&gt;&lt;/tr&gt;
                                   &lt;/form&gt;&lt;p&gt;&lt;/p&gt;';
                       }//end elseif    
                          elseif($stateName =='Colorado') {
                          $form = '&lt;form action="testsad.php" method="post"&gt;';
                          $form .= '&lt;table&gt;';
                          $form .= '&lt;tr&gt;&lt;td&gt;Select a city to visit:&lt;/td&gt;&lt;td&gt;
                                   &lt;select name=\'cityName\'&gt;';
  
                                  foreach ($cityCO_Array as $cityChoice =&gt; $cityName) {
                          $form .= '&lt;option value="'.$cityChoice.'"&gt;'.$cityName.'&lt;/option&gt;';
                                  }//end foreach loop
                          $form .= '&lt;tr&gt;&lt;td style="text-align:center;"&gt;&lt;input type="submit" value="Submit" /&gt;&lt;/td&gt;&lt;/tr&gt;';
  
                          $form .= '&lt;/select&gt;
                                   &lt;/td&gt;&lt;/tr&gt;
                                   &lt;/form&gt;&lt;p&gt;&lt;/p&gt;';
                       }//end elseif                                         
                       $var = 0;
                  }//end else statement
  
                  return $form;
              }//end display_form()
  
              function display($state)
              {
                  $analyze = '&lt;h1&gt;';
                  if ($state['stateName'] == 'Pennsylvania') {
  
                      $analyze .= '&lt;tr&gt;&lt;th&gt;'.$state['formName'].', here is info for: '.$state['stateName'].'&lt;/th&gt;&lt;/tr&gt;';  
  
  
                      $analyze .= '&lt;p&gt;Pennsylvania is a wonderful state! It is a part of the appalachian mountains and has many traditions.&lt;br/&gt;&lt;br/&gt; The new state Capitol drew rave reviews. Its dome was inspired by the domes of St. Peter\'s Basilica in Rome and the United States Capitol. President Theodore Roosevelt called it "the most beautiful state Capital in the nation" and said, "Its the handsomest building I ever saw" at the dedication. In 1989, the New York Times praised it as "grand, even awesome at moments, but it is also a working building, accessible to citizens ... a building that connects with the reality of daily life".&lt;br/&gt;&lt;br/&gt;
                      Pennsylvania accounts for nine percent of wooded areas in the United States. In 1923 President Calvin Coolidge established the Allegheny National Forest under the authority of the Weeks Act of 1911 in the northwest part of the state in Elk, Forest, McKean, and Warren Counties for the purposes of timber production and watershed protection in the Allegheny River basin. The Allegheny is the state\'s only national forest.
                      &lt;br/&gt;James Buchanan, of Franklin County, the only bachelor President of the United States, was the only one to be born in Pennsylvania. The Battle of Gettysburg, the major turning point of the Civil War—took place near Gettysburg. An estimated 350,000 Pennsylvanians served in the Union Army forces along with 8,600 African American military volunteers.
                      Pennsylvania was also the home of the first commercially drilled oil well. In 1859, near Titusville, Pennsylvania, Edwin L. Drake successfully drilled the well, which led to the first major oil boom in United States history.&lt;/p&gt;';  
                  }//end if
                  if ($state['stateName'] == 'California') {
  
                      $analyze .= '&lt;tr&gt;&lt;th&gt;'.$state['formName'].', here is info for: '.$state['stateName'].'&lt;/th&gt;&lt;/tr&gt;';  
  
  
                      $analyze .= '&lt;p&gt;California\'s Mount Whitney measures as the highest peak in the lower 48 states. Its most famous climb is Mount Whitney Trail to the 14,495 feet summit. Wilderness permits are required.
                                   In 1925 a giant sequoia located in California\'s Kings Canyon National Park was named the nation\'s national Christmas tree. The tree is over 300 feet in height.
                                   More turkeys are raised in California than in any other state in the United States.&lt;/p&gt;';  
                  }//end if
                  if ($state['stateName'] == 'Florida') {
  
                      $analyze .= '&lt;tr&gt;&lt;th&gt;'.$state['formName'].', here is info for: '.$state['stateName'].'&lt;/th&gt;&lt;/tr&gt;';  
  
  
                      $analyze .= '&lt;p&gt;Much of Florida is situated on a peninsula between the Gulf of Mexico, the Atlantic Ocean, and the Straits of Florida. 
                          Its geography is marked by a coastline, by the omnipresence of water and the threat of hurricanes. Florida has the longest coastline in the contiguous United States, encompassing approximately 1,350 miles (2,170 km), and is the only state to border both the Gulf of Mexico and the Atlantic Ocean. 
                          Much of the state is at or near sea level and its terrain is characterized by sedimentary soils. 
                          The climate varies from subtropical in the north to tropical in the south.&lt;/p&gt;';    
                  }//end if
                  if ($state['stateName'] == 'Colorado') {
  
                      $analyze .= '&lt;tr&gt;&lt;th&gt;'.$state['formName'].', here is info for: '.$state['stateName'].'&lt;/th&gt;&lt;/tr&gt;';  
  
  
                      $analyze .= '&lt;p&gt;Colorado is bordered by the northwest state of Wyoming to the north, the midwest states of Nebraska and Kansas to the northeast and east, on the south by New Mexico a small portion of the southern state of Oklahoma, on the west by Utah, and Arizona to the southwest. 
                          The four states of Colorado, New Mexico, Arizona, and Utah meet at one common point known as the Four Corners, which is known as the heart of the American Southwest. 
                          Colorado is one of only three U.S. states with no natural borders, the others being neighboring Wyoming and Utah. 
                          Colorado is noted for its vivid landscape of mountains, forests, high plains, mesas, canyons, plateaus, rivers, and desert lands.&lt;/p&gt;'; 
                  }//end if    
                  if ($state['stateName'] == 'Texas') {
  
                      $analyze .= '&lt;tr&gt;&lt;th&gt;'.$state['formName'].', here is info for: '.$state['stateName'].'&lt;/th&gt;&lt;/tr&gt;';  
  
  
                      $analyze .= '&lt;p&gt;Due to its size and geologic features such as the Balcones Fault, Texas contains diverse landscapes that resemble both the American South and Southwest.
                          Although Texas is popularly associated with the Southwestern deserts, less than 10% of the land area is desert.
                          Most of the population centers are located in areas of former     prairies, grasslands, forests, and the coastline. 
                          Traveling from east to west, one can observe terrain that ranges from coastal swamps and piney woods, to rolling plains and rugged hills, and finally the           desert and mountains of the Big Bend.&lt;/p&gt;'; 
                  }//end if                       
                  $analyze .= '&lt;/h1&gt;';
                  $analyze .= '&lt;p&gt;&lt;a href="testsad.php"&gt;Try again!&lt;/a&gt;&lt;/p&gt;';
  
                  return $analyze;
              }//end analyze()
  
  
              //page display
  
              if( empty ($_POST) )
              {
                  echo display_form();
  
  
              }//end if
              else
              {
                  echo display($_POST);
                  echo display_form();
              }//end else
  
          ?&gt;
  </code></pre>