title: PHP: array with an if statement inside
body: <p>Hi all, </p>
  
  <p>Here's my code: </p>
  
  <pre><code>if ($value==0)
  {
          $array = array(
          "NAMES"            =&gt; array("John", "Sara", "Mark"), 
          "LASTNAMES"      =&gt; array ("Smith", "Lockwood", "Grant")
          );
  }
  else 
  {
          $array = array(
          "NAMES"            =&gt; array("John", "Sara", "Mark"), 
          "LASTNAMES"      =&gt; array ("Smith", "Lockwood", "Grant"),
          "ITEMPURCHASED"      =&gt; array ("DVD", "Book", "Comic")
           );   
  }
  </code></pre>
  
  <p>As you can see I'm reapeating the whole array code just because the ITEMPURCHASED element. </p>
  
  <p>Is there a way not to repeat the whole array code? Can an if be used inside the array which adds just the ITEMPURCHASED element? If so, how? </p>
  
  <p>Thanks a ton </p>