Can't get computed field to work This is the code:

$number-&gt;field_max['und'][0]['value'];

$array = array(
    "7mm Shorty over 7mm Jump" =&gt; 10,
    "7mm Shorty over 5mm Jump" =&gt; 14,
    "7mm Jump" =&gt; 13,
    "5mm Shorty over 5mm Jump" =&gt; 16,
    "5mm Shorty over 3mm Jump or 7mm Shorty over 3mm Jump" =&gt; 19,
    "5mm Jump" =&gt; 19,
    "3mm Shorty over 3mm Jump" =&gt; 20,
    "3mm Shorty over 2mm jump" =&gt; 24,
    "3mm Jump" =&gt; 24,
    "2mm Jump" =&gt; 27,
);

foreach ($array as $i) {
    $smallest[$i] = abs($i - $number);
}
asort($smallest);

$closest = key($smallest);

$suit = array_search($closest, $array);

$entity_field[0]['value'] = $suit;


$display_output = $entity_field_item['value'];


I want it to display the value closest to the number entered in the field_max field.
In response to various comments and other answers, here is some code that ought to work:

$number = $entity-&gt;field_max['und'][0]['value'];

$array = array(
  "7mm Shorty over 7mm Jump" =&gt; 10,
  "7mm Shorty over 5mm Jump" =&gt; 14,
  "7mm Jump" =&gt; 13,
  "5mm Shorty over 5mm Jump" =&gt; 16,
  "5mm Shorty over 3mm Jump or 7mm Shorty over 3mm Jump" =&gt; 19,
  "5mm Jump" =&gt; 19,
  "3mm Shorty over 3mm Jump" =&gt; 20,
  "3mm Shorty over 2mm jump" =&gt; 24,
  "3mm Jump" =&gt; 24,
  "2mm Jump" =&gt; 27,
);
$smallest_value = PHP_INT_MAX;
$closest_value = -1;
foreach ($array as $val) {
  if(abs($val - $number) &lt; $smallest_value) {
    $smallest_value = abs($val - $number);
    $closest_value = $val;
  }
}
$entity_field[0]['value'] = $closest_value;


After this code is done, $closest_value should be set to the value closest to the initial value.  You can output this however you like.  In the display value field, there should be something like $display_output = $entity_field_item['value'];