I have an array that looks like this,
Array
(
[0] => 849710414
[1] => 849710726
[2] => 849710744
[3] => 849712728
[4] => 849713005
[5] => 849713439
[6] => 849714856
[7] => 849714924
[8] => 849716371
[9] => 849716441
[10] => 849717118
[11] => 849719043
[12] => 849719187
[13] => 849722865
[14] => 849723412
[15] => 849723777
[16] => 849725052
[17] => 849726294
[18] => 849726457
[19] => 849726902
[20] => 849728239
[21] => 849728372
[22] => 849728449
[23] => 849730353
[24] => 849733625
)
These are ID’s that I need to add to an URL to navigate around the site, the IDs are the results that get returned from a user’s search, the user then clicks on a search result and has the option of going to the next search result are look at the previous one, now I though I would be able to do this, by doing
<a href="<?=next($array);?>">Next</a>
<a href="<?=prev($array);?>">Prev</a>
How ever I does not seem to recognise what the current result ID I am looking at is to work what is next and previous? Does anybody now how I can solve this?
next()andprev()deal with the internal pointer of the array while your script is processing.What you need to do is find out which index of the array you are currently viewing, (
array_search()) then add 1 to get the next value, and subtract 1 to get the previous value.Your HTML: