title: php stdClass object Nested object for child values
body: <p>I am working on stdClass Object in laravel. I have to combine values from two table. i.e. first one containing some questions and other one is containing their multiple choice answers. How to combine the result in a way that the questions object could contain its answer object as nested object. I want the structure like that:</p>
  
  <pre><code>stdClass Object
  (
  [question_id] =&gt; 4
  [title] =&gt; How to add data?
  [options] =&gt; Array
  (
  [0] =&gt; stdClass Object
  (
  [id] =&gt; 1
  [question_id] =&gt; 4
  [option_title] =&gt; By any device
  )
  
  [1] =&gt; stdClass Object
  (
  [id] =&gt; 2
  [question_id] =&gt; 4
  [option_title] =&gt; By mobile
  )
  
  [2] =&gt; stdClass Object
  (
  [id] =&gt; 3
  [question_id] =&gt; 4
  [option_title] =&gt; By Laptop
  )
  )
  stdClass Object
  (
  [question_id] =&gt; 5
  [title] =&gt; Where to add data?
  [options] =&gt; Array
  (
  [0] =&gt; stdClass Object
  (
  [id] =&gt; 1
  [question_id] =&gt; 5
  [option_title] =&gt; Lahore
  )
  
  [1] =&gt; stdClass Object
  (
  [id] =&gt; 2
  [question_id] =&gt; 5
  [option_title] =&gt; Karachi
  )
  
  [2] =&gt; stdClass Object
  (
  [id] =&gt; 3
  [question_id] =&gt; 5
  [option_title] =&gt; Multan
  )
  
  );
  </code></pre>