how to manipulate this array ??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

how to manipulate this array ??

Post by PHPycho »

Hello forums !!
Case:
I had the array as:

Code: Select all

$array = array(1 => array('key1' => 'xxx', 'status' => 'Y'), 2 => array('key1' => 'yyy', 'status' => 'N'), 3 => array('key1' => 'zzz', 'status' => 'N')...);
I would like to find the next and previous key in the array according to the status. ie

Code: Select all

function getNextKey(){
    //should return the 2 as 1 key has status Y (Yes)
    // if 1 key has status 'N' then it should return 1 key
        // ie it should be the next to the last key with status Y
}
function getCurrentKey(){
    // should return 1
    // if 2 key too had status 'Y' then it should return 2
       // ie it should be the last key with status Y.
}
function getPrevkey(){
    // should return null
    // if 2 key too had status 'Y' then it should return 1
        // ie it should be the prev to the last key with status Y
}
Additionally:
Status key with status = Y means that key 's operation has been performed.
so if key 1 has status Y then next would be obviously 2 to be performed next..
For getNextKey, it should be the next to the last key with status Y
for getPrevkey, it should be the prev to the last key with status Y
for getCurrentKey, it should be the last key with status Y.

How to accomplish this type of array manipulation??
Thanks in advance for the valueable help.
Post Reply