Never put code in the database. It is impossible to maintain and debug, and you spend hours wasting your time.
The computed field gives you the option to add the code to a custom module.
My answer used these three fields added to the content type:
- Temp (machine name field_temp, integer, multi-value)
- Highest (machine name field_highest, computed, int)
- Lowest (machine name field_lowest, computed, int)
Method:
Create a custom module (just module and info files), then add this to the module file:
function computed_field_field_highest_compute(&$entity_field, $entity_type, $entity, $field, $instance, $langcode, $items) {
$temps = field_get_items($entity_type, $entity, 'field_temp');
if (count($temps)) {
$max = $temps[0]['value'];
foreach($temps as $temp) {
$max = $temp['value'] > $max ? $temp['value'] : $max;
}
$entity_field[0]['value'] = $max;
}
}
function computed_field_field_lowest_compute(&$entity_field, $entity_type, $entity, $field, $instance, $langcode, $items) {
$temps = field_get_items($entity_type, $entity, 'field_temp');
if (count($temps)) {
$min = $temps[0]['value'];
foreach($temps as $temp) {
$min = $temp['value'] < $min ? $temp['value'] : $min;
}
$entity_field[0]['value'] = $min;
}
}
Read the documentation page for the computed field module to see the naming convention for adding a custom function. The function name is also visible in the field settings.
In the two functions I refer to 'field_temp'. It is the machine name of the multi-value field holding the temperature values.