We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

naz on 03/10/08


Tagged

array


Versions (?)


previous -next keys in array


Published in: PHP 


This function return array with previous and next values from certain point, if pointer is last element in array function return first element.

  1. function array_navigate($array, $key)
  2. {
  3. $keys = array_keys($array);
  4. $index = array_flip($keys);
  5.  
  6. $return = array();
  7.  
  8. $return['prev'] = (isset($keys[$index[$key]-1])) ? $keys[$index[$key]-1] : end($keys);
  9.  
  10. $return['next'] = (isset($keys[$index[$key]+1])) ? $keys[$index[$key]+1] : current($keys);
  11.  
  12. return $return;
  13. }

Report this snippet 

Comments

RSS Icon Subscribe to comments
Posted By: abc on March 12, 2008

this is realy very good URL

You need to login to post a comment.