How to set an Arrays internal pointer to a specific position? PHP/XML -
I'm trying to create a bit of site using XML rather than a database.
I would like to create a front and back button which will work in relation to the content I have displayed.
I want to set the pointer to a specific position to be able to navigate the PHP function next () and the previous () as well as current (), but relative to the current page .
$ list = array ('page1', 'page2', 'page 3') For example if I display the content of page 2 How to tell PHP that I am in the $ list [1] so that the next ($ list) will show page 3?
In advance thank you
If your array is always indexed (like 'Page 1 'Always index' at 0), it is quite simple:
$ list = array ('page1', 'page2', 'page3', 'page4', 'page5'); $ Current page = 3; // 'page 4' while (key ($ list)! == $ current page) Next ($ list); // Unless there is a match I do not rely on auto-indexing because there is always a chance that the automatic index can change. You must define the keys clearly:
$ list = array ('1' => 'Page 1', '2' => 'Page 2', '3 '= & Gt;' Page 3 ',); Edit: If you want to test the values of the array (instead of the keys), then use it: (current ($ list)! = = $ Current page) Next ($ list);
Comments
Post a Comment