Less-expensive way to set up defaults in lists etc?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Margaret MacDonald

    #1

    Less-expensive way to set up defaults in lists etc?

    I'm currently setting up default selections in <select> lists by
    passing an array of those defaults as keys ( 'valuefoo' => true ) as
    an argument to the function that sets up the list. Then, as I build
    each <option>, I call array_key_exist s ( thisoptionvalue ,
    arrayofdefaults ) to check whether to include the
    'selected="sele cted"' string.

    So the code looks something like

    Routine ( array( 'valuefoo' => true, 'valuebar' => true ) ) ;
    .....

    function Routine ( $defaultvals )
    {
    for ( $i= etc. )
    echo '<option....' . ( array_key_exist s( 'curroptval',
    $defaultvals ) ? 'selected="sele cted"' : '' ) . etc ' ;
    }

    (I've elided a lot of syntax, but you get the idea)

    That seems slow and tedious. Does anyone know a cheaper way?

    Thanks,
    Margaret
    --
    (To mail me, please change .not.invalid to .net, first.
    Apologies for the inconvenience.)
Working...