title: How to create nested PHP value object? (class)
body: <p>I would like to create the following using class syntax:</p>
  
  <pre><code>$resp = new stdclass;
  
  $resp-&gt;CategoryListResp-&gt;category[0]-&gt;categoryId = 1;
  $resp-&gt;CategoryListResp-&gt;category[0]-&gt;categoryName = "Spel"; 
  $resp-&gt;CategoryListResp-&gt;category[0]-&gt;iconUri = "PictoSpel.png";
  
  $resp-&gt;CategoryListResp-&gt;category[1]-&gt;categoryId = 2;
  $resp-&gt;CategoryListResp-&gt;category[1]-&gt;categoryName = "Transport";
  $resp-&gt;CategoryListResp-&gt;category[1]-&gt;iconUri = "PictoTransport.png";
  </code></pre>
  
  <p>Should be easy but I cannot find the syntax for this.
  I will later output $resp in json format. I am aware I can also use arrays for this...</p>
  
  <p>The json output shall be:</p>
  
  <pre><code>{"CategoryListResp":{"category":[{"categoryId":1,"categoryName":"Spel","iconUri":"PictoSpel.png"},{"categoryId":2,"categoryName":"Transport","iconUri":"PictoTransport.png"}]}}
  </code></pre>