Im trying to build a little site using XML instead of a database.
I would like to build a next and prev button which will work relative to the content I have displa
Using the functions below, you can get the next and previous KEYs of the array. If current key is not valid or it is the last (first - for prev) key in the array, then:
The functions are cyclic.
function getNext(&$array, $curr_key)
{
$next = 0;
reset($array);
do
{
$tmp_key = key($array);
$res = next($array);
} while ( ($tmp_key != $curr_key) && $res );
if( $res )
{
$next = key($array);
}
return $next;
}
function getPrev(&$array, $curr_key)
{
end($array);
$prev = key($array);
do
{
$tmp_key = key($array);
$res = prev($array);
} while ( ($tmp_key != $curr_key) && $res );
if( $res )
{
$prev = key($array);
}
return $prev;
}