title: php multidimensional array get data
body: <p>I need some help getting data from a multidimensional array in PHP. This array is filled with questions, and answers to those questions. Each question can have multiple answers, but the number of answers is different for most questions. This is the var_dump of it:</p>
  
  <pre><code>object(CommandResponse)#3 (3) 
  { 
      ["success"]=&gt; bool(true) 
      ["message"]=&gt; string(6) "Got it" 
      ["value"]=&gt; array(2) 
      { 
         [0]=&gt; array(3) 
         { 
             ["questionId"]=&gt; string(2) "25" 
             ["question"]=&gt; string(9) "Question 1" 
             ["answers"]=&gt; array(2) 
             { 
                 [0]=&gt; array(2) 
                 { 
                     ["answerId"]=&gt; string(1) "1" 
                     ["answer"]=&gt; string(9) "Answer 1" 
                 } 
                 [1]=&gt; array(2) 
                 { 
                    ["answerId"]=&gt; string(2) "18" 
                    ["answer"]=&gt; string(22) "Answer 2 for question 1" 
                 }
           }
      } 
      [1]=&gt; array(3) 
      { 
          ["questionId"]=&gt; string(2) "26" 
          ["question"]=&gt; string(9) "Question 2" 
          ["answers"]=&gt; array(1) 
          { 
              [0]=&gt; array(2) 
              { 
                  ["answerId"]=&gt; string(2) "17" 
                  ["answer"]=&gt; string(9) "Answer 2" 
              } 
          } 
      } 
  }
  </code></pre>
  
  <p>I would like to get something like this from it:</p>
  
  <pre><code>Question 1
    Answer 1
    Answer 2
  Question 2
    Answer 1
    Answer 2
  </code></pre>
  
  <p>So far I've tried:</p>
  
  <p>Get the question like this: <code>print $myArray-&gt;value[0]['question'];</code>
  Get the first answer like this: <code>print $myArray-&gt;value[0]['anwsers'][0]['answer'];</code></p>
  
  <p>I've also tried to loop it in some foreach loop, but I'm not getting anything good from it.</p>
  
  <pre><code>foreach ($myArray-&gt;value as $key =&gt; $value)
  {
      print $value['question'].' - ';
      print $value['answers'][0]['answer'].'&lt;br /&gt;';
  }
  </code></pre>