Jump to content

How do you order an array's results alphabetically?


Chezshire

Recommended Posts

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; 

?>

 

 

 

 

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

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; 

?>

 

 

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[#]

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.