Add option selected disabled in PHP

2019-02-20 02:39发布

问题:

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>?

回答1:

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