If you have no way of changing your array structure, you could do the following by "creating" a new array with just the values of the original array, via array_values()
$vals = array_values($my_array);
$match_key = array_search("blue", $vals);
echo "PREV: ". $vals [($match_key - 1)] . "\n";
echo "CURR: ". $vals[$match_key] ."\n";
echo "NEXT: ". $vals [($match_key + 1)] . "\n";
Which returns:
PREV: green
CURR: blue
NEXT: purple
Now you'll need to do key handling/etc to ensure the code doesn't throw any errors and handles your keys in a subtle way.
There are various other ways (inspired by this post) that harnesses in-built functions, although seemingly taking longer to process:
$match_key = array_search("blue", $my_array);
// loop through and set the array pointer to the $match_key element
while (key($my_array) !== $match_key) next($my_array);
$current = $my_array[$match_key];
$prev = prev($my_array);
next($my_array); // set the array pointer to the next elem (as we went back 1 via prev())
$next = next($my_array);
Which returns the previous, current & next as below:
CURRENT: blue
PREVIOUS: green
NEXT: purple