I'm sure that this is soooo easy. However, I've been scratching me head over it for a few days, staring blankly at the online PHP manual 😉
So... If I have an associative array thus (dummy data to illustrate problem):
$colours = array(
"R" => "RED",
"B" => "BLUE",
"Y" => "YELLOW",
"G" => "GREEN"
);
I then have a variable, $col that holds the current colour. The value of this is always known by the script.
What I would like to do is return the previous and next colour, so that if $col were "Y", the previous colour would be "B" and the next colour would be "G".
Ideally, I would like to loop around if I get to the start or end of the array, so that for example, if $col were "R", then the previous colour would be "G", whereas if $col were "G", the next colour would be "R".
I'm sure that it's a one or two liner that involves the prev() and next() functions, but I've gone utterly blank.
Any help welcome 🙂
thanks