title: array - undefined index in sorting php result
body: <p>I wrote an API where I return questions from one table and all the answers from another related to that question. </p>
  
  <p>As it needs to sort them like multidimensional array 
  I worked with logic but it throws an error on last "foreach",</p>
  
  <p>My code:</p>
  
  <pre><code> $results = $this-&gt;getQuestionRepository()
          -&gt;createQueryBuilder('a')
          -&gt;getQuery()
          -&gt;getResult();
  
      $questionResults = $results[0];
  
      $answers = $this-&gt;getAnswer($qresults); // gets all of the answers by question
  
      $mappedQuestions = [];
      foreach ($questionResults as $result){
          $mappedQuestions[$result-&gt;getId()];
      }
  
      foreach ($questions as $question){
  
          $questionId = $question-&gt;getQuestion()-&gt;getName();
          $mappedQuestions[$questionId];
      }
  
      $results[0] = array_values($mappedQuestions);
  
      return $results;
  </code></pre>
  
  <p>and it throws:</p>
  
  <blockquote>
    <p>Notice: Undefined index: Name</p>
  </blockquote>
  
  <p>and the problem is in</p>
  
  <blockquote>
    <p>$mappedQuestions[$questionId];</p>
  </blockquote>
  
  <p>As results in first dump query I get:</p>
  
  <p><a href="https://i.stack.imgur.com/mI7TQ.png" rel="nofollow noreferrer">results</a></p>