Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $names = array("bob", "john", "colly", "sparky");
- $options = array();
- foreach ($names as $name) {
- $options[] = sprintf('<option value="%s"> %s </option>' , $name , $name);
- }
- ?>
- <select>
- <?=implode("\n",$options);?>
- </select>
- Finally, one last way.
- I prefer to make each string an item in an array.
- Then implode that array into a single string.
- JS would call that array.join instead of implode.
- The "\n" inserts the invisible "new line" character
- that pushes text onto new lines and makes the
- "view source" look "neater" if you want it to be.
Add Comment
Please, Sign In to add comment