title: Can I include a function inside of another function?
body: <p>Is it possible to include one function inside another? To learn functions, I'm trying to create a combat sequence using PHP. The sequence would look like this:</p>
  
  <ol>
  <li>Dice would roll, assigning numbers to variables;</li>
  <li>Hero1 attack results are printed; </li>
  <li>Dice would roll, assigning numbers to variables;</li>
  <li>Hereo2 attack results are printed;</li>
  <li>Dice would roll, assigning numbers to variables;</li>
  <li>Hero3 attack results are printed.</li>
  </ol>
  
  <p>The dice rolling would be an automated function. Here is the code:</p>
  
  <pre><code>&lt;?
  rollSim();
  combatSim();
  
  function rollSim() {
      $hAttack = rand(1,20);
      $mDefend = rand(1,20);
      $mAttack = rand(1,20);
      $hDefend = rand(1,20);
      $mDamage = rand(10,25);
      $hDamage = rand(1,20);
  } // end rollSim
  
  function combatSim() {
      rollSim();
      if ($hAttack&gt;$mDefend) {
          print "Hero hit monster for $hDamage damage.&lt;br&gt;";
      } else if ($hAttack&lt;=$mDefend) {
          print "Hero missed monster.";
      }
  } // end combatSim
  
  ?&gt;
  </code></pre>