Chezshire Posted June 5, 2009 Share Posted June 5, 2009 I'm trying to get my Array which list the characters to list 'Alphabetically', but am unable to do so. At the moment, everyone who has replies is featured as I'd like but they're names are listing in alphabetical order as I'd like. I've tried some sort()s and other things but nothing has worked. Any help is appreciated (I'm starting college to study web this Month!) <?php if ($featuring && $charid) 'ORDER BY featuring, codeName'; { ?> <tr><td align="right" width="100"><p><font color="#A5B9D5"><b>Who:</b></font></p></td><td width="10"></td> <td><p><font color="#A5B9D5"><?php list ($featuring, $charList) = linkCharsAdvanced($featuring, $id); echo $featuring; ?> Quote Link to comment https://forums.phpfreaks.com/topic/161131-how-do-you-order-an-arrays-results-alphabetically/ Share on other sites More sharing options...
Maq Posted June 5, 2009 Share Posted June 5, 2009 Check out - sort. Quote Link to comment https://forums.phpfreaks.com/topic/161131-how-do-you-order-an-arrays-results-alphabetically/#findComment-850276 Share on other sites More sharing options...
Chezshire Posted June 5, 2009 Author Share Posted June 5, 2009 Thank you for the suggested direction Maq, I've been googling 'Sort' 'how to order an array alphabetically' and having little success (I don't know what i'm doing, and i just do lots of trial and error. I will now go off and look at this new option which I doubt i would have found by myself. I will also likely be back here in an hour with more questions. Thank you for the assist! Wish me luck! -Chez Quote Link to comment https://forums.phpfreaks.com/topic/161131-how-do-you-order-an-arrays-results-alphabetically/#findComment-850283 Share on other sites More sharing options...
Chezshire Posted June 5, 2009 Author Share Posted June 5, 2009 I attempted to use the sort option again (but I don't grock 'SORT' what so ever.) I'm not getting the following error listing, everything is still working as it was, but this error reads above the array i'm trying to have display/sort alphabetically. 'Warning: sort() expects parameter 1 to be array, string given in /home/content/z/a/n/zanland/html/xpg/messages/displayX.php on line 111 CHANT, SPEED, OBSIDIAN, ANIMA' The names 'CHANT, SPEED, OBSIDIAN, ANIMA' is what i'm trying to get to list as 'ANIMA, CHANT, SPEED, OBSIDIAN'. Below is my revised code: <?php if ($featuring && $charid) 'ORDER BY featuring, codeName'; { ?> <tr><td align="right" width="100"><p><font color="#A5B9D5"><b>Who:</b></font></p></td><td width="10"></td> <td><p><font color="#A5B9D5"><?php list ($featuring, $charList) = linkCharsAdvanced($featuring, $id); sort($featuring); for($i=0; $i<8; $i++) { print $narray[$i] . ""; } echo $featuring; ?> Quote Link to comment https://forums.phpfreaks.com/topic/161131-how-do-you-order-an-arrays-results-alphabetically/#findComment-850305 Share on other sites More sharing options...
trq Posted June 5, 2009 Share Posted June 5, 2009 Obviosuly, $featuring isn't an array. Can we see your linkCharsAdvanced() function? Quote Link to comment https://forums.phpfreaks.com/topic/161131-how-do-you-order-an-arrays-results-alphabetically/#findComment-850315 Share on other sites More sharing options...
.josh Posted June 5, 2009 Share Posted June 5, 2009 The names 'CHANT, SPEED, OBSIDIAN, ANIMA' is what i'm trying to get to list as 'ANIMA, CHANT, SPEED, OBSIDIAN'. Last time I checked, S comes after O. Quote Link to comment https://forums.phpfreaks.com/topic/161131-how-do-you-order-an-arrays-results-alphabetically/#findComment-850322 Share on other sites More sharing options...
Chezshire Posted June 6, 2009 Author Share Posted June 6, 2009 Hello Thorpe - I COMPLETELY forgot that I built that as a function, or as an attempted a while back (THANK YOU! YOU ARE SUPER HELPFUL). I honestly thought i was calling an ARRAY. Below is my wacky function which I want to list characters alphabetically (So it would work like Crayon mentioned). I have the functions called out from the main page in a file called functions.php which someone on here told me to do last year. [#] function linkCharsAdvanced ($text, $post) { list($codenameList,$codenameID,$appearanceList) = listChars(); $text = preg_replace("/\//","}",$text); $charids = array(); $replaceArray = array(); FOR ($z=0; $z < count ($codenameList); $z++) { $thisName = addslashes($codenameList[$z]); $searchName = preg_replace("/\./","\.",$thisName); $searchName = preg_replace("/\//","}",$thisName); $text = preg_replace("/$searchName([, \.;:\)&])/","[[$z]]$1", $text); $text = preg_replace("/$searchName$/","[[$z]]", $text); $replaceArray[$z] = "<a href=\"/cerebra/display.php?id=$codenameID[$z]\" id='cerebra_$codenameID[$z]_$post'>$codenameList[$z]</a>"; $thisName = preg_replace("/\./","\.",$codenameList[$z]); } // end FOR FOR ($z=0; $z < count ($codenameList); $z++) { $oldtext=$text; $text = preg_replace("/\[\[$z\]\]/","$replaceArray[$z]", $text); if ($oldtext != $text) { array_push($charids, $codenameID[$z]); } } // end FOR $text = preg_replace("/}/","/", $text); return array(stripslashes($text), $charids); } // end FUNCTION[#] Quote Link to comment https://forums.phpfreaks.com/topic/161131-how-do-you-order-an-arrays-results-alphabetically/#findComment-850331 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.