title: Access php multidimensional array key based on a variable string
body: <p>I have stored the XML path to items in a string like this: <code>response-&gt;items-&gt;item</code>.</p>
  
  <p>What I need to do is to access an array called $xml_array like this:</p>
  
  <p>$xml_array['response']['items']['item']</p>
  
  <p>When I write it in the code it works. The thing is that I want it to be done on the fly.</p>
  
  <p>I use this to convert <code>response-&gt;items-&gt;item</code> to <code>['response']['items']['item']</code>:</p>
  
  <pre><code>$xml_path = 'response-&gt;items-&gt;item';
  $explode_path = explode('-&gt;', $xml_path);
  $correct_string = false;
  
  foreach($explode_path as $path) {
     $correct_string .= '[\''.$path.'\']';
  }
  </code></pre>
  
  <p>the problem is that I can't access <code>$xml_array</code> by doing this: <code>$xml_array[$correct_string]</code></p>
  
  <p>So I end up with this:</p>
  
  <pre><code>$xml_tag = 'title';
  $xml_path = 'response-&gt;items-&gt;item';
  
  $correct_string = '$items = $xml2array';
  
  $explode_path = explode('-&gt;', $xml_path);
  
  foreach($explode_path as $path) {
      $correct_string .= '[\''.$path.'\']';
  }
  $correct_string .= ';';
  
  eval($correct_string);
  foreach($items as $item) {
      echo $item[$xml_tag].'&lt;br /&gt;';
  }
  </code></pre>
  
  <p>and access the <code>$xml_array</code> array through <code>$items</code> array. Is there any way I can do this and avoid using eval()?</p>
  
  <p>Thanks in advance!</p>