I have an array where I want to get the next value.
$sorting = array(0 => "H 101", 1 => "S 101", 2 => "R 172", 3 => "D 141", 4 => "T 101", 5 => "K 101", 6 => "A 182", 7 => "G 101");
I have the current value taken from a SELECT statement. I have tried array_search but I can’t get it to do want I want.
Let’s say my current value is S 101, how can I get it to give me “R 172” as the next value which I then can use in a new SELECT statement.
And I also want it to get back to the first value (H 101) if the current value is the last (G 101).
Why have you explicitly specified the indices? These would be the same had you not done it.
From what I understand, array_search would be suitable for what you want.
HOWEVER, if I understand you correctly you’re looping through this array and making queries on it. How about posting what you want in terms of query result, as there may be a better solution (i.e. MySQL
IN())