Determine Array Key For Field Type Programatically Different fields have different keys for the actual 'value' of the field. For example a regular text field has:

$node-&gt;field_my_text_field[$node-&gt;language]['value']


Whereas if I have a field using the email module, it looks like this:

$node-&gt;field_my_email_field[$node-&gt;language]['email']


I'm working on a function that saves a whole bunch of fields, and I want it to be as flexible as possible, it has a loop that looks like this:

foreach($person_details as $k=&gt;$detail) {
    $node-&gt;{'field_'.$k}[$node-&gt;language][0]['value'] = $detail;
}


This is no good at the moment since 'value' is hard coded, and I have some fields in there that use 'email' and a few others from various modules.

Is there any way to know in advance what the key should be?
My solution ended up being this:

$field_structure = field_info_field($field_name);
$keys = array_keys($field_structure['storage']['details']['sql']['FIELD_LOAD_CURRENT']['field_data_'.$field_name]);


This gives an array of all the posible data columns for $field_name, where $field_name is something like 'field_my_field'.