I have the following results page from the previous form:
<?php
//Get the form results (which has been converted to an associative array) from the $_POST super global
$musicgenres = $_POST['music'];
//Sort the values by rank and keep the key associations.
asort($musicgenres, SORT_NUMERIC );
//Loop over the array in rank order to print out the values.
foreach($musicgenres as $music => $rank)
{
echo "$music is your $rank choice";
echo "<br>";
}
?>
Here is an example of the output (without the bullets):
- Rap is your 1 choice
- Rock is your 2 choice
- Jazz is your 3 choice
- etc....
I'm thinking that putting this into a table would be easier and cleaner if I assign these values to incremental variables like below:
e.g.
- $musicrank1 = rap
- $musicrank2 = rock
- $musicrank3 = jazz
- etc....
But is there an argument for using a table to say $musicrank[1] instead of $musicrank1 and iterate over the table if I wanted to?
$musicrank = array_flip($musicgenres);
php.net/manual/en/function.array-flip.php Also I think question is more fit for stackoverflow. – AmazingDreams yesterday