Guest User

Untitled

a guest
Dec 13th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. <?php
  2. $names = array("bob", "john", "colly", "sparky");
  3. $options = array();
  4. foreach ($names as $name) {
  5. $options[] = sprintf('<option value="%s"> %s </option>' , $name , $name);
  6. }
  7. ?>
  8.  
  9. <select>
  10. <?=implode("\n",$options);?>
  11.  
  12. </select>
  13.  
  14. Finally, one last way.
  15. I prefer to make each string an item in an array.
  16. Then implode that array into a single string.
  17. JS would call that array.join instead of implode.
  18. The "\n" inserts the invisible "new line" character
  19. that pushes text onto new lines and makes the
  20. "view source" look "neater" if you want it to be.
Add Comment
Please, Sign In to add comment