title: PHP - Query single value per iteration or fetch all at start and retrieve from array?
body: <p>I have a function that looks something like this:</p>
  
  <pre><code>//iteration over scales
  foreach ($surveyScales as $scale)
  {
      $surveyItems = $scale-&gt;findDependentRowset('SurveyItems');
  
      //nested iteration over items in scale
      foreach ($surveyItems as $item)
      {
          //retrieve a single value from a result table and do some stuff
          //depending on certain params from $item / $scale
      }
  }
  </code></pre>
  
  <p><strong>QUESTION</strong>: is it better to do a db query for every single value within the inner foreach or is it better to fetch all result values into an array and get the value from there?</p>