title: PHP: Getter and Setter while using Arrays?
body: <p>I'm extremely new to php so excuse my code if you think it is a mess but I've been trying to figure this out for hours. </p>
  
  <p>I am trying to use the getter and setter method to pull functionality from a class then use an array to create new objects based off the class. <code>$_GET</code> is to get the input <code>foodNumber</code> from a HTML form which determines which position in the array is chosen. So if 0 is inputted on the form, it represents <code>Salad</code>, if 2 is entered on the form it should mean <code>Vegetables</code>.</p>
  
  <p>So in my mind, the <code>$foodObject</code> is creating a new object from the <code>class FoodArray</code>. I am trying to make the objects be in an array, so in this case <code>$foodArray</code>. But I don't know how to input values through an array using the getter setter method using the class functions or how to call them.
  Thanks in advance!</p>
  
  <pre><code> &lt;?php
  
  class FoodArray {
  
  private $foodValue;
  
  public function setFoodValue($x){
  $this-&gt;foodValue=$x;
  }
  
  public function getFoodValue(){
  return $this-&gt;foodValue;
  }
  }
  
  
  $foodNumber = $_GET['foodNumber']; 
  
  $foodObject = new FoodArray;
  
   $foodArray = array ("Salad", "Vegetables", "Pasta", "Pizza", "Burgers");
   $foodArray=$foodObject-&gt;getFoodValue();
  
   echo "The number you chose is ". $foodNumber;
   echo "The food item you choose is".$foodArray[$foodNumber]; 
  
  ?&gt;
  </code></pre>
  
  <p>/////HTML FORM/////</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  
  &lt;form action="class_with_getter_and_setter.php" method="get"&gt;
  &lt;b&gt;Choose a number between 0-4 and get a mystery food!&lt;/b&gt;
  &lt;input type="text" name="foodNumber"&gt;
  
  &lt;input type="submit"&gt;
  
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>