R
Reaction score
0

Profile posts Latest activity Postings About

  • Creating List Box with <Optgroup> option using PHP:

    <?php
    $ar=array('romance'=>array('Unfaithful','A walk to remember','Notebook'),'thriller'=>array('The Omen','Orphan'),'war'=>array('Gladiator','Troy'));
    echo 'Size of an Array'.sizeof($ar);
    echo '<br>';
    echo "<select name='list1'>";
    foreach($ar as $key=>$value)
    {
    echo'<optgroup label='.ucfirst($key).'>';
    foreach($value as $v)
    {
    echo '<option value='.$v.'>';
    if(is_array($v))
    {
    foreach($v as $f)
    {
    echo $f;
    }
    }
    else
    {
    echo ucfirst($v);
    }
    echo '</option>';
    }
    echo '</optgroup>';
    }
    echo '</select>';
    ?>

    It will create Option with optgroup label as Romance,thriller and Mystery and necessay movies as options...Hope this will help someone...
  • Loading…
  • Loading…
  • Loading…
Top