[SOLVED] Forcing Array Sort

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
blacksnday
Forum Contributor
Posts: 252
Joined: Sat Jul 30, 2005 6:11 am
Location: bfe Ohio :(

[SOLVED] Forcing Array Sort

Post by blacksnday »

Heya everyone :)

I am having trouble getting the below to sort and show the way i want it to
in the web browser.

Code: Select all

$newposts = array ( $row['name'] => "Name", $row['lova'] => "Past Loves", $row['news'] => "Bash" );
    ksort ($newposts);
     foreach ( $newposts as $postfield => $postinput )
    {
     echo "$postinput: $postfield<br>";
    }
What I want it to show as would be:
Name: blah blah Past Loves: blahblah
Bash:

Even having it be:
Name: blah blah
Past Loves: blahblah
Bash:
would be just fine.

Right now what it is doing is sorting based on the text grabbed from the DB,
with the Name and Bash fields moving ontop of each other depending
on what was grabbed from the database.

I have tried different types of sort with no luck to make it stay consistent.
Any help is appreciated :)
Last edited by blacksnday on Thu Aug 18, 2005 8:06 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your code places the content as the key, if you flipped their creation order in the array, it may help. I'm not sure what the sort is really for since it would appear you only have 1 record within that array at a time..
User avatar
blacksnday
Forum Contributor
Posts: 252
Joined: Sat Jul 30, 2005 6:11 am
Location: bfe Ohio :(

Post by blacksnday »

Ahh, silly me :P

Your right, I didnt need the sort, I took it out and now it shows as I want.
Thanks!
Post Reply