when using variable: Fatal error: Cannot use string offset as an array
<p>The following piece of code:</p>

<pre><code>$field = 'field_total_comments_added';
$current_user_count = $user_data-&gt;$field['und']['0']['value'];
</code></pre>

<p>returns an error: Fatal error: Cannot use string offset as an array</p>

<p>if I just use:</p>

<pre><code>$current_user_count = $user_data-&gt;field_total_comments_added['und']['0']['value'];
</code></pre>

<p>the code works just fine. In order to use some custom functionality I have to use the variable displayed in the first code block. How can I solve this? </p>

<p>Please tell me if the problem isn't clear to you.</p>

<p>Thanks in advance for your assistance</p>
