The following piece of code:
$field = 'field_total_comments_added';
$current_user_count = $user_data->$field['und']['0']['value'];
returns an error: Fatal error: Cannot use string offset as an array
if I just use:
$current_user_count = $user_data->field_total_comments_added['und']['0']['value'];
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?
Please tell me if the problem isn't clear to you.
Thanks in advance for your assistance