title: PHP Help Building Multi-Dimensional Array in For Loop
body: <p>I am newish to PHP and web development.  I am struggling a bit on how to best program this multi-dimensional array in PHP using for loops.</p>
  
  <p>Essentially, it is a review website.  I am using Bootstrap to render the data in different tabs.  The data is being called via a jquery ajax request and the PHP page is returning JSON.  Handlebars is being used to render the data in a template.</p>
  
  <p>In the end, I'd like to send the data in roughly this format:  </p>
  
  <pre><code>{ 
      review: {
          reviewstotal: INT,
          count: INT,
          summary: {
              //iterated
              tab: INT,
              [{ 
                  Question:,
                  Value:,
                  Color: ,
                  Percent:,
              },
              {
                  Question:,
                  Value:,
                  Color: ,
                  Percent:,
              }]
          }
      }
  }
  </code></pre>
  
  <p>Where I'm struggling is at the "summary" section.  The "Questions" are in an array, and I have the "Values" as another array.  The color value would come from an if statement checking the "Value" and set a css value in the template. The percent is the "Value" multiplied by 10.  Here is what I have so far to generate the array.</p>
  
  <pre><code>$array = array();
  $color ="";
  
  for ($x = 0; $x &lt;= 5; $x++) {
      $summary= [];
  
      if ( ${"q{$x}"} &lt;= 40){
        $color = "danger";
      } else if ( ${"q{$x}"} &gt;= 70){
        $color = "success";
      } else {
        $color = "warning";
      }
  
      $summary = array_push ($array, $aquest[$x], ${"q{$x}"}, $color, ${"q{$x}"}*10);
  }
  </code></pre>
  
  <p>What I get as output is:</p>
  
  <pre><code>"summary": ["The facilities of the school adequately provide for a positive learning/working experience.",null,"danger",0,
  "School provides adequate access to teaching materials without any extra expense by the teacher (books, lab supplies, art supplies, materials, copying, etc.)","9.50","danger",95,
  "School is well funded to provide students and faculty with adaquate materials to support their course offering.","9.50","danger",95,
  "Parent community is actively involved in supporting the school's mission and their child's education endeavors.","9.00","danger",90,
  "Classroom student to teacher ratios are kept low.","8.75","danger",87.5,null,"7.63","danger",76.3]
  </code></pre>
  
  <p>What I am trying to achieve though is that each "Question" section is wrapped in it's own array.  Like:</p>
  
  <pre><code>"summary": [["The facilities of the school adequately provide for a positive learning/working experience.",null,"danger",0],
  ["School provides adequate access to teaching materials without any extra expense by the teacher (books, lab supplies, art supplies, materials, copying, etc.)","9.50","danger",95],
  ["School is well funded to provide students and faculty with adequate materials to support their course offering.","9.50","danger",95],
  ["Parent community is actively involved in supporting the school's mission and their child's education endeavors.","9.00","danger",90],
  ["Classroom student to teacher ratios are kept low.","8.75","danger",87.5,null,"7.63","danger",76.3]]
  </code></pre>
  
  <p>And then I can add a consistent key to each of them.</p>