Changing Arrays

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 45
Joined: Wed Mar 12, 2003 7:17 pm

Sat Mar 15, 2003 11:01 am

I want to access all the content of an array backwards. I've come up with two possibilities.

One, I could start a loop counting backwards from the last entry in the array... but I don't know how to get the number of elements in an array.

Two, I could take all of the elements in an array and transfer them backwards to another array. Then start at one.

Any other idea's? What I have is an array where array[0] is a username and array[1] is a message...then array[2] is a username, and array[3] is the next message... I want to display the second to last array element, then the last...then the 4th to last...then the 3rd to last..etc... so all the new messages are on top.

Edit: Better do you fopen a file to add to the top...but not replace anything?

New php-forum User
New php-forum User
Posts: 164
Joined: Tue Aug 27, 2002 8:25 pm
Location: Ontario, Canada

Sat Mar 15, 2003 3:23 pm

Well I know the function array_reverse() will reverse the order of your elements... maybe that would help you.

Post Reply