title: Nesting a variable number of keys to create a multidimensional array without using eval()
body: <p>I've created a function that returns a nested array based in the values and keys of another two arrays and assigns a third value to the deepest key (hope it makes any sense with the code):</p>
  
  <pre><code>function myfunc_build_array($mydata,$keys,$value)
  {
      $newarr=array();
  
      foreach ($mydata as $data)
      {
          $evalvar='$newarr';     
          foreach ($keys as $key)
          {           
              $evalvar.="['".$data[$key]."']";
          }
          $evalvar.='=$value;';
          eval($evalvar); 
      }
      return $newarr;
  }
  </code></pre>
  
  <p>So, i.e. if we have:</p>
  
  <pre><code>$mydata=array(
        0=&gt;array('section'=&gt;'NS1','subsection'=&gt;'NS1A','employee'=&gt;'2812','name'=&gt;'Bob'),
        1=&gt;array('section'=&gt;'NS1','subsection'=&gt;'NS1A','employee'=&gt;'2811','name'=&gt;'Bib'),
        2=&gt;array('section'=&gt;'NS1','subsection'=&gt;'NS1B','employee'=&gt;'2718','name'=&gt;'Bub'),
      );
  
  $keys= array('section','subsection','employee');
  </code></pre>
  
  <p>The result for myfunc_build_array($mydata,$keys,"active"); is:</p>
  
  <pre><code>array(1) {
    ["NS1"]=&gt;
    array(2) {
      ["NS1A"]=&gt;
      array(2) {
        [2812]=&gt;
        string(6) "active"
        [2811]=&gt;
        string(6) "active"
      }
      ["NS1B"]=&gt;
      array(1) {
        [2718]=&gt;
        string(6) "active"
      }
    }
  }
  </code></pre>
  
  <p>It works fine but as I usually avoid using eval(), I was wondering if there is a better way to do it, more elegant or faster.</p>