Page 1 of 1

[SOLVED] Forcing Array Sort

Posted: Thu Aug 18, 2005 12:08 am
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 :)

Posted: Thu Aug 18, 2005 7:50 am
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..

Posted: Thu Aug 18, 2005 8:06 am
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!