![]() |
get the previous and next array key with a keyword - 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: get the previous and next array key with a keyword (/showthread.php?tid=34296) |
get the previous and next array key with a keyword - El Forum - 09-25-2010 [eluser]Bartolo![/eluser] Hi guys, i have a list of customers. which can be all customers, or a list from the search. when you open a customer i want navigate previous and next. first of all i have a function that saves all the id's found to a session: Code: $_SESSION['customer_ids'] = $this->customers_model->get_allcustomer_ids($search); print_r($_SESSION['customer_ids']); Code: Array how to get the previous / current / next array key...??? what i want is a link (when i'm in customer 1166) a link to customer 786. and off course the previous one. The current customer_id is: Code: $customer['customer_id']; i was already trying with array_search and stuff but couldn't get it working. Hopefully someone can help me out.... Thanks in advance!!!! regards, Bart EDIT: php.net told me that array_search returns an array key. but when i use: Code: foreach($_SESSION['customer_ids'] as $array) { it shows the word "customer_id". so how do i get the array key corresponding with my current record?? get the previous and next array key with a keyword - El Forum - 09-25-2010 [eluser]jmadsen[/eluser] next() is pretty cool :-) http://php.net/manual/en/function.next.php next(), prev(), end() are explained here. Do you need the value, or the key? --- Google search words: "php array next element" get the previous and next array key with a keyword - El Forum - 09-25-2010 [eluser]Bartolo![/eluser] Hi, what i need is the next and previous customer_id in the array. i already found the next functions but i think i'm using the multidimensional array's the wrong way... this: Code: foreach($_SESSION['customer_ids'] as $array) { current returns: 1165 next returns.....nothing.... get the previous and next array key with a keyword - El Forum - 09-25-2010 [eluser]jmadsen[/eluser] right, so read up on the stuff I posted: $my_array = $_SESSION[‘customer_ids’]; $my_customer = next($my_array); $my_customer[1] is your value, I think. Maybe I'm not clear what you are after, but it seems like php array coding from here... get the previous and next array key with a keyword - El Forum - 09-27-2010 [eluser]Bartolo![/eluser] Thanks for your help...it was easier than i thought... This is the result: Code: foreach ($_SESSION['customer_ids'] as $key => $value) |