Iurie Iurie - 8 months ago 37
PHP Question

Add option selected disabled in PHP

I have a form with a dropdown field in PHP with this array:

$field["options"] = array(
array("value" => "Chişinău", "text" => "Chişinău", "depth" => 0),
array("value" => "Bălţi", "text" => "Bălţi", "depth" => 0),
array("value" => "Comrat", "text" => "Comrat", "depth" => 0),
...
array("value" => "Ungheni", "text" => "Ungheni", "depth" => 0)
);


How to add as a first option the
<option selected disabled>Choose one</option>
?

Answer Source
$field["options"] = array(
    array("value" => " ", "text" => "Choose one", "depth" => 0, "selected" => "selected", "disabled" => "disabled"),
    //...rest other option code
);