![]() |
Finding an item's position in an array, and then returning previous and next items - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Finding an item's position in an array, and then returning previous and next items (/showthread.php?tid=7255) |
Finding an item's position in an array, and then returning previous and next items - El Forum - 04-01-2008 [eluser]Daniel H[/eluser] Guys, I wonder if anyone can explain how I can do this presumably straight forward thing. Consider an array like this, e.g. Code: Array On a page, I'm displaying work example whose ID is 27946, i.e. key[1]. How then would I firstly locate this value in the array, and then return ID 27945 (next) and ID 27947 (previous)? Many thanks, Dan. Finding an item's position in an array, and then returning previous and next items - El Forum - 04-01-2008 [eluser]xwero[/eluser] from php.net array_search comments Code: function fktMultiArraySearch($arrInArray,$varSearchValue){ Code: function surrounding_rows($array,$key) Code: $rows = surrounding_rows($files,fktMultiArraySearch($files,27946)); Finding an item's position in an array, and then returning previous and next items - El Forum - 04-01-2008 [eluser]Daniel H[/eluser] That works beautifully - thank you so much for helping. |