Re: alphabetical order?
| From: | Chad Winger | Date: | Mon, 16 Sep 2002 12:31:07 +0000 |
| Subject: | Re: alphabetical order? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-116510@lists.php.net to get a copy of this message | ||
Ok lets see if i follow, cuz this isn't working for me. I think I'm missing
something conceptually. Someone tell me when I mistake.
//this is example of the text in the file
01|Brescello|stadium|city|
02|Aglianese|stadium|city|
//this part of the script reads each line, takes out the | and creates the
array $squads
$list = fgets($fd, 4096);
$squads = explode("|", $list);
//so now in theory I would have the following
$squads[0] = 01
$squads[1] = Brescello
$squads[2] = stadium
$squads[3]= city
//now i need a new array $alphabetical
$alphabetical = $squads[1][0];
//now i need to sort $alphabetical
sort ($alphabetical);
//so now I'm guessing I would have the following
$alphabetical[0] = $squads[1][0];
so here is my final code
<html>
<body>
<select>
<?php
include ("C:\path\to\config.php");
$fd = fopen ($teams, "r");
while (!feof ($fd))
{
$list = fgets($fd, 4096);
$squads = explode("|", $list);
$alphabetical = $squads[1][0];
sort ($alphabetical);
echo '<OPTION
VALUE="'.$alphabetical[0].'">'.$squads[1].'</OPTION>'."\n";
}
fclose ($fd);
?>
</select>
</html>
</body>
When I run that i get this:
<OPTION VALUE="B">Brescello</OPTION>
<OPTION VALUE="A">Aglianese</OPTION>
plus the error message sort() expects parameter 1 to be array
Im obviously missing a step or 20 :(
I've tried different things following the manual as per your suggestions,
such as array_push and ksort, but im just getting more and more errors..any
more suggestions?