Skip to content
WJunction - Webmaster Forum

Do you use these PHP functions with arrays ??

Status
Not open for further replies.
Ok so ill tell you the truth here.. i never heard of these functions until erlier today lol

what this basically does is allow you to paginate an array.. yes paginate

here's the function list and then some examples of them

PHP:
next();
prev();
current();
reset();
end();

heres some usage examples

PHP:
$array = array('litewarez','katz','phaze','others');
//Next
echo current($array);//litewarez
echo next($array); //katz
echo end($array);  //others
echo prev($array); //phaze
echo reset($array);//litewarez

next($array);
next($array);
next($array);
prev($array);
next($array);

echo current($array); // others

this navigation is stored like sessions so your position is always held.

heres a full example of usage

PHP:
$aFruit = array ('Tried' => array('Apple', 'Kiwi'),
                    'Not Tried' => array('Pear', 'Orange', 'Banana')
                     );

while($aChild = key($aFruit))
{
    while($szItem = current($aFruit[$aChild]))
    {
        echo current($aFruit[$aChild]) . '<br />';
        next($aFruit[$aChild]);
    }
    next($aFruit);
}

hope i brought a little more tips to the table :P
 

5 comments

so when usung a foreach loop your going threw a whole array but by using these functions php will remember the current position the you navigated to. aka the word pagination :P
 
Status
Not open for further replies.

About the author

L
Active Member · Joined
I am a skilled programmer within PHP,HTML,CSS,MYSQL and also the owner of several websites Programming, Football...
1,367
Messages
1
Reactions
38
Points

Advertise on WJunction

Reach 1000's of webmasters, hosts & affiliates. Banner & sponsored-thread slots available.

Contact us
Back
Top Bottom