0

This is the HTML in a php file.

<select id="efHidden" style="width:80px;" class="text ui-widget-content ui-corner-all">
     <option value="0">off</option>
     <option value="1">on</option>
</select>

and I have a php variable $arr having the required values to be shown

1
  • It is all these smaller things that .Net does for you that are the hard part in the transition from .Net to PHP. Keep at it. :) Commented Dec 22, 2010 at 12:23

3 Answers 3

1
<?php $arr = array('off' => 0, 'on' => 1); ?>

<select>
    <?php 
       foreach($arr as $k => $v)
       {
           echo "<option value=\"$v\">$k</option>";
       }
    ?>
</select>
Sign up to request clarification or add additional context in comments.

Comments

1
<?php
$arr = array('0' => 'off', '1' => 'on');
?>
<select id="efHidden" style="width:80px;" class="text ui-widget-content ui-corner-all">
                        <?php foreach ($arr as $key=>$value) {?>
                        <option value="<?php echo $key; ?>"><?php echo $value; ?></option>
                        <?php } ?>
                       </select>

Comments

0
$arr = array('1' => 'Option One', '2' => 'Option Two', '3' => 'Option Three');
foreach($arr as &$item){ echo '<option value="'.$item[0].'">'.$item[1].'</option>'; }

1 Comment

-1 - $item will be a string, not an array, and also there's no need to access $item by reference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.