Output array values using function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bubblediana
    New Member
    • Apr 2010
    • 2

    Output array values using function

    Code:
    <?php
    $county = array (´Kent´,´West Susses´,´East Sussex´,´Sommerset´,´Hampshire´,´London´,´Essex´);
    $hear = array (´Google´,´Other Search Engine´,´Magazine´,´Recommendation´);
    
    function createDropdown($arr, $frm) {
    
    echo '<select name="'.$frm.'" id="'.$frm.'"><option value="">Select one…</option>
    <option value="'.$value.'">'.$value.'</option></select>';
    
    }
    
    ?>
    
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    
    <form  id="ddown" name="ddown" method="post" action="createDropdown.php"></form>
    <label  for="frmcounty">County:</label>
    
    <label  for="frmhowhear">How did you hear about us?:</label>
    
    
    
    
    
    </body>
    </html>
    Last edited by Atli; Apr 1 '10, 04:57 AM. Reason: Added [code] tags.
  • chathura86
    New Member
    • May 2007
    • 227

    #2
    change the function to this

    Code:
    function createDropdown($arr, $frm) {
    
    	echo '<select name="'.$frm.'" id="'.$frm.'">';
    
    	echo '	<option value="">Select one…</option>';
    
    	foreach ($arr as $value)
    		echo '<option value="'.$value.'">'.$value.'</option>';
    
    	echo '</select>';
    
    }
    to use it

    Code:
    <?php createDropdown($county, 'selCountry'); ?>
    put the above code where you want the dropdown

    Regards
    Chathura Bamunusinghe

    Comment

    • bubblediana
      New Member
      • Apr 2010
      • 2

      #3
      Thank you Chathura Bamunusinghe .

      It's really work!i hope u don't mind to guide me if i need help from you. :)

      -bubblediana-

      Comment

      • chathura86
        New Member
        • May 2007
        • 227

        #4
        sure that's what bytes is for.

        post your problems here and me or some one else will
        try to assist you.

        and please mark the best answer when ever you can, because it
        will help other to find the solution

        Regards
        Chathura Bamunusinghe

        Comment

        Working...