I attempting to write a foo that will edit/create an array element in an ORDERED BUT NON CONTIGUOUS numeric array, calculating the new OR EDITED element's value based on the previous arrays value.

for example
$values[thisKey]=$values[PREVIOUSKey] +5;

This would be easy, if the arrays were contiguous (ie.:1,2,3,4,5,6...) but in fact they can be (1,2,5,10,11,12,13,15...) :/

applying the above pattern, it should end up functioning like this:
$values[10]=$values[5] +5;

the following is the logic of my foo:
Code:
foo($keyToMakeOrEdit){
   $defaultStartValue=10;
   ksort($this->dataArray); //make sure array is in order
   if (!isset($this->dataArray[$keyToMakeOrEdit])){   // make NEW array element;
             $base=end($this->dataArray); //get the value of the last array element
     }
    else{    //we are now editing an existing key
                // need to find a way to  move the array pointer to $keyToMakeOrEdit HOW?????
               $base=prev($this->dataArray); //get the value of the last array element
     }
    reset($this->dataArray);  reset the data array , just as a precaution
    $this->dataArray[$keyToMakeOrEdit]=($base!==false) ?   $base+5 : $defaultStartValue  ;  // if the array is empty  set value to the default , else set it to the LAST ($base) key +5;
}
I just cant think of a PHP function that would let me move the array pointer to specific key (10) so that I could move it back one element and obtain that elements value. I realize , I could just 'compress' my array using array_values and thus have a contiguous set of keys, but unfortunately I also need to preserve the keys. Any suggestions?