Jump to content
Larry Ullman's Book Forums

Echoing Sorted Array With <Option> Tag


Recommended Posts

Hi everyone. I'm trying to echo the values of an array inside HTML's <option> tag. The following should be echod:

 

<option value="Moose Jaw,SK,Canada">Moose Jaw,SK,Canada</option>
<option value="Prince Albert,SK,Canada">Prince Albert,SK,Canada</option>
<option value="Regina,SK,Canada">Regina,SK,Canada</option>
<option value="Saskatoon,SK,Canada">Saskatoon,SK,Canada</option>
 
The code I attempted was:
 
<!DOCTYPE html>
<html>
<body>
<?php
$sk=array("Saskatoon","Regina","Moose Jaw", "Prince Albert");
sort($sk);
foreach ($sk as $value) {
echo '<option value="'.$value.',SK,Canada">'.$value.',SK,Canada</option>';
echo "<br>";
}
?>
</body>
</html>
 
Pls. note that the values of the array are not sorted alphabetically. The output, however, should be sorted in ascending format and be within the <option> tag after adding the province and country.
 
Any help will be highly appreciated.
 
 
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...