title: PHP: Updating an associative array though a class function?
body: <p>I want to be able to update an associative array within an object based on function input, but I'm at a loss for how to do this. Here's my problem. Let's say there's this data container in my object:</p>
  
  <pre><code>private $vars = Array
  (
    ['user_info'] = Array
    (
      ['name'] =&gt; 'John Doe'
      ['id'] =&gt; 46338945
      ['email'] =&gt; 'johndoe@example.com'
      ['age'] =&gt; 35
    )
    ['session_info'] = Array
    (
      ['name'] =&gt; 'session_name'
      ['id'] =&gt; 'mGh44Jf0nfNNFmm'
    )
  )
  </code></pre>
  
  <p>and I have a public function <code>update</code> to change these values:</p>
  
  <pre><code>public function update($keys, $changeValueTo) {
    if (!is_array($keys)) {
      $keys = array($keys);
    }
    nowWhat();
  }
  </code></pre>
  
  <p>Ultimately, I just want to be able to convert something like this</p>
  
  <pre><code>array('user_info', 'name')
  </code></pre>
  
  <p>into this:</p>
  
  <pre><code>$this-&gt;vars['user_info']['name']
  </code></pre>
  
  <p>so I can set it equal to the <code>$equalTo</code> parameter.</p>
  
  <p>This usually wouldn't be a problem, but in this scenario, I don't know the schema of the <code>$vars</code> array so I can't write a <code>foreach</code> statement based on a fixed number of keys. I also can't just make <code>$vars</code> public, because the function needs to do something within the object every time something is changed.</p>
  
  <p>I'm worried that this is a recursive scenario that will involve resorting to <code>eval()</code>. What would you recommend?</p>