LemonStand Documentation

option_state

function option_state($current_value, $selected_value)

Returns selected="selected" string if the parameter values are equal. Use this function for programming OPTION elements inside SELECT tag.

Parameters

  • $current_value - mixed. Specifies a value of current OPTION element.
  • $selected_value - mixed. Specifies selected value.

Return value

Returns string.

Examples

The following code creates a select element for selecting a state.

<select>
	<? foreach ($states as $state): ?>
	<option <?= option_state($current_state, $state->id) ?> value="<?= h($state->id) ?>"><?= h($state->name) ?></option>
	<? endforeach ?>
</select>

Next: post
Previous: open_form
Return to Reference