Question
Help with alphabetic sorting of array value
Hi All,
I've created a form with a drop down list populated from a text file
array. I want to alphabetically sort the options based on the array
value but I don't know how to do that. Below is the code, any help
would be appreciated.
> <?php
> $textfile = 'car_makes.txt';
> if (file_exists($textfile) && is_readable($textfile)) {
> // read the file into an array named $namearray
> $namearray = file($textfile);
> }
> else
> {
> echo "Can't open $textfile";
> }
> ?>
>
> <form id="form1" name="form1" method="post" action="">
> <select name="choice" id="choice">
> <option value="">Select your choice</option>
> <?php
> foreach ($namearray as $name)
> {
> echo "<option value='$name'>$name</option>\n";
> }
> ?>
> </select>
> </form>
TIA
Brett
I've created a form with a drop down list populated from a text file
array. I want to alphabetically sort the options based on the array
value but I don't know how to do that. Below is the code, any help
would be appreciated.
> <?php
> $textfile = 'car_makes.txt';
> if (file_exists($textfile) && is_readable($textfile)) {
> // read the file into an array named $namearray
> $namearray = file($textfile);
> }
> else
> {
> echo "Can't open $textfile";
> }
> ?>
>
> <form id="form1" name="form1" method="post" action="">
> <select name="choice" id="choice">
> <option value="">Select your choice</option>
> <?php
> foreach ($namearray as $name)
> {
> echo "<option value='$name'>$name</option>\n";
> }
> ?>
> </select>
> </form>
TIA
Brett
