Sunday, June 24, 2012

PHP in_array example

<?php
$people = array("1", "2", "3", "4", "5");
//$people = array(1,2,3,4,5);
?>
<select name="ad" multiple="multiple" style="height:100px;width:100px;">
<option value="0">Select Value</option>
<?php
for($intI=0;$intI<5;$intI++)
{
if(in_array($intI,$people))
{
    $selected = "selected='selected'";
}
?>
    <option value="<?php echo $intI;?>" <?php echo $selected;?>><?php echo $intI;?></option>
<?php
}
?>
</select>

No comments:

Post a Comment

Please mention your comments.......