Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

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?

share|improve this question
    
using an array makes "here are your top 100 choices" a LOT easier to code –  Dan Pichelman yesterday
    
$musicrank = array_flip($musicgenres); php.net/manual/en/function.array-flip.php Also I think question is more fit for stackoverflow. –  AmazingDreams yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.