I've got the following code:
What I require the page to do is to put whatever values are typed into the form into the array and sort them in alphabetical order. The line below is the line i *think* is causing the problem:
If i type actual values in the speech marks then it sorts those values, but how can i get it to sort the values that are typed into the form? I thought it'd just be a case of typing txt1 txt2 etc but that doesn't work
Am i missing something somewhere?
Code:
<?php
$txt1 = $_POST['txt1'];
$txt2 = $_POST['txt2'];
$txt3 = $_POST['txt3'];
$txt4 = $_POST['txt4'];
$txt5 = $_POST['txt5'];
$txt6 = $_POST['txt6'];
$txt7 = $_POST['txt7'];
$txt8 = $_POST['txt8'];
$txt9 = $_POST['txt9'];
$txt10 = $_POST['txt10'];
?>
<table><form name="form1" method="post" action="<?php echo $PHP_SELF;?>">
<tr><td><input type="text" name="names[]" id="txt1" /></td></tr>
<tr><td><input type="text" name="names[]" id="txt2" /></td></tr>
<tr><td><input type="text" name="names[]" id="txt3" /></td></tr>
<tr><td><input type="text" name="names[]" id="txt4" /></td></tr>
<tr><td><input type="text" name="names[]" id="txt5" /></td></tr>
<tr><td><input type="text" name="names[]" id="txt6" /></td></tr>
<tr><td><input type="text" name="names[]" id="txt7" /></td></tr>
<tr><td><input type="text" name="names[]" id="txt8" /></td></tr>
<tr><td><input type="text" name="names[]" id="txt9" /></td></tr>
<tr><td><input type="text" name="names[]" id="txt10" /></td></tr>
<tr><td><input type="submit" value="Submit" />
</form></table>
<?php
$names = array("","","","","","","","","","");
sort($names);
foreach ($names as $key => $val) {
echo "names[" . $key . "] = " . $val . "\n";
}
?>
What I require the page to do is to put whatever values are typed into the form into the array and sort them in alphabetical order. The line below is the line i *think* is causing the problem:
$names = array("","","","","","","","","","");
If i type actual values in the speech marks then it sorts those values, but how can i get it to sort the values that are typed into the form? I thought it'd just be a case of typing txt1 txt2 etc but that doesn't work

Am i missing something somewhere?