title: PHP - lookup array contents with dot syntax
body: <p>Does anybody see anything wrong with the following function? (<strong>Edit</strong>: no, I don't think anything is wrong, I am just double-checking since this will be inserted into a very common code path.)</p>
  
  <pre><code>function getNestedVar(&amp;$context, $name) {
      if (strstr($name, '.') === FALSE) {
          return $context[$name];
      } else {
          $pieces = explode('.', $name, 2);
          return getNestedVar($context[$pieces[0]], $pieces[1]);
      }
  }
  </code></pre>
  
  <p>This will essentially convert:</p>
  
  <pre><code>$data, "fruits.orange.quantity"
  </code></pre>
  
  <p>into:</p>
  
  <pre><code>$data['fruits']['orange']['quantity']
  </code></pre>
  
  <p>For context, this is for a form utility I am building in Smarty.  I need the name for the form also so I need the string to be in a key-based form, and can't directly access the Smarty variable in Smarty.</p>