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
Here's the complete @tjunglc 's approach with looping:
protected function getPrevNext($aArray,$key)
{
$aKeys = array_keys($aArray); //every element of aKeys is obviously unique
$aIndices = array_flip($aKeys); //so array can be flipped without risk
$i = $aIndices[$key]; //index of key in aKeys
if ($i > 0) $prev = $aArray[$aKeys[$i-1]]; //use previous key in aArray
if ($i < count($aKeys)-1) $next = $aArray[$aKeys[$i+1]]; //use next key in aArray
if (!isset($prev)) $prev = end($aArray);
if (!isset($next)) $next = reset($aArray);
return array($prev,$next);
}
Oh and thankx @tjunglc for this :)