title: Laravel: Create Array
body: <p>I have  a multi questions with multi answers on the same page and I want to display all data so I create a new array to pass it to the view the new array will contain all question with the answers if the question has no answer then the value will be null and if it has answer the value should be as the value that stored on the database.the problem that the new array stores the last question data only.</p>
  
  <pre><code>$exist_data = RatingDatum::where($check_data)-&gt;get();    /*get all the previous data I have to answers here for the two questions only the third question have no answer */
  
          $datum = array();
  ]        foreach ($question_angles as $index =&gt; $angle) {
              if (!empty($exist_data)){
                  foreach ($exist_data as $row) {
                      if ( $row['question_angle_id'] == $angle-&gt;id) {
                          $datum[$index]['question_angle_id'] = $angle-&gt;id;
                          $datum[$index]['answer_id'] = $row['answer_id'];
                          $datum[$index]['comment'] = $row['comment'];
                          $datum[$index]['reference'] = $row['reference'];
                      } else {
                          $datum[$index]['question_angle_id'] = $row['question_angle_id'];
                          $datum[$index]['answer_id'] = $row['answer_id'];
                          $datum[$index]['comment'] = null;
                          $datum[$index]['reference'] = null;
  
                      }
  
                  }
  
              } 
          }
  </code></pre>
  
  <p><strong>dd($datum);</strong></p>
  
  <pre><code>array:3 [▼
    0 =&gt; array:4 [▼
      "question_angle_id" =&gt; 2
      "customize_question_id" =&gt; null
      "comment" =&gt; null
      "reference" =&gt; null
    ]
    1 =&gt; array:4 [▼
      "question_angle_id" =&gt; 2
      "customize_question_id" =&gt; 7666
      "comment" =&gt; "test"
      "reference" =&gt; "test"
    ]
    2 =&gt; array:4 [▼
      "question_angle_id" =&gt; 2
      "customize_question_id" =&gt; null
      "comment" =&gt; null
      "reference" =&gt; null
    ]
  ]
  </code></pre>
  
  <p>the data should look like this the first two question have answers but the last question not have answer so the values is null:</p>
  
  <pre><code> array:3 [▼
        0 =&gt; array:4 [▼
          "question_angle_id" =&gt; 1
          "answer_id" =&gt;2
          "comment" =&gt; null
          "reference" =&gt; null
        ]
        1 =&gt; array:4 [▼
          "question_angle_id" =&gt; 2
          "answer_id" =&gt; 6
          "comment" =&gt; "test"
          "reference" =&gt; "test"
        ]
        2 =&gt; array:4 [▼
          "question_angle_id" =&gt; 3
          "answer_id" =&gt; null
          "comment" =&gt; null
          "reference" =&gt; null
        ]
      ]
  </code></pre>