title: How do I build a dynamic variable with PHP?
body: <p>I'm trying to build a dynamic variable in PHP and despite looking at a number of the questions on the matter already here on StackOverflow I'm still stumped... :/</p>
  
  <p>Variable variables is something I've never quite understood - hopefully someone here can point me in the right direction. :)</p>
  
  <pre><code>$data['query']-&gt;section[${$child['id']}]-&gt;subsection[${$grandchild['id']}]-&gt;page[${$greatgrandchild['id']}] = "Fluffy Rabbit";
  </code></pre>
  
  <p>Onviously the above does not work but if I hard code a variable as such:</p>
  
  <pre><code>$data['query']-&gt;section[0]-&gt;subsection[3]-&gt;page[6] = "Very Fluffy Rabbit";
  </code></pre>
  
  <p>...then all is fine, so obviously I'm not building my dynamic variable correctly. Any ideas?</p>
  
  <p>UPDATE:</p>
  
  <p>Hmm, ok I should have pointed out that these are not keys in an array - I'm addressing nodes in the XML using an ID which is specified as an attribute for each node, so the XML has the following structure:</p>
  
  <pre><code>&lt;subtitles&gt;
  &lt;section id="0"&gt;
  &lt;subsection id="0"&gt;
  &lt;page id="1"&gt;My content that I want to write&lt;/page&gt;
  &lt;page id="2"&gt;My content that I want to write&lt;/page&gt;
  &lt;page id="3"&gt;My content that I want to write&lt;/page&gt;
  &lt;/subsection&gt;
  &lt;/section&gt;
  &lt;/subtitles&gt;
  </code></pre>
  
  <p>Hopefully that helps explain things a little better. :)</p>