0

I am very new to Php platform,The question may be a simple one.

I have an array having three variables, and i have stored it as

$options = array('S' =>"Seminar" , 'A'=>"Athletics",'C' =>"Conference");

Now i need to access this array variables inside the dropdown menu. Drop down menu is as shown below.

<span class="custom-dropdownSm custom-dropdown--emerald custom-dropdown--large">
    <select class=" custom-dropdown__select--emerald" id="Assessment_Name" >               
        <option value="0" selected="selected">Select</option>
    </select>

Any help appreiated.

1
  • 3
    use foreach for display all options from array $options.. Commented Sep 23, 2014 at 7:19

3 Answers 3

4

After Select this line write

foreach($options as $key => $val) {
        echo '<option value="'.$key.'">'.$val.'</option>';
    }
Sign up to request clarification or add additional context in comments.

Comments

2

You can use this

<?php foreach($options as $option) { ?>
   <option><?php echo $option; ?></option>
<?php } ?>

in case of need in value

<?php foreach($options as $key=>$option) { ?>
   <option value="<?php echo $key; ?>"><?php echo $option; ?></option>
<?php } ?>

Comments

0
<?php

$options = array('S' =>"Seminar" , 'A'=>"Athletics",'C' =>"Conference");

?>

<span class="custom-dropdownSm custom-dropdown--emerald custom-dropdown--large">
    <select class=" custom-dropdown__select--emerald" id="Assessment_Name" >               
        <option value="0" selected="selected">Select</option>

        <?php 
            foreach($options as $key => $val) {
                echo '<option value="'.$key.'">'.$val.'</option>';
            }
        ?>

    </select>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.