我有这样的数组。
array(
1 => array("United States","Antigua and Barbuda","Anguilla","American Samoa","Barbados","Bermuda","Bahamas","Canada","Dominica","Dominican Republic","Grenada","Guam","Jamaica","Saint Kitts and Nevis","Cayman Islands","Saint Lucia","Northern Mariana Islands","Montserrat","Puerto Rico","Sint Maarten (Dutch part)","Turks and Caicos Islands","Trinidad and Tobago","Saint Vincent and the Grenadines","Virgin Islands, U.S.","Virgin Islands, U.S.")
,7 => array("Russian Federation","Kazakhstan")
,20 => array("Egypt")
,27 => array("South Africa")
,30 => array("Greece")
,31 => array("Netherlands")
,32 => array("Belgium")
,33 => array("France")
,34 => array("Spain")
,36 => array("Hungary")
,39 => array("Italy")
,40 => array("China")
,41 => array("Switzerland")
,43 => array("Austria")
,44 => array("United Kingdom","Guernsey","Isle of Man","Jersey")
,45 => array("Denmark")
,46 => array("Sweden")
,47 => array("Norway","Svalbard and Jan Mayen")
,48 => array("Poland")
)
我希望html select元素中的值具有与父键相同的值。现在我正在使用
$builder->add('callingCode', 'choice', array(
'choices' => $thatarray));
但是会产生像这样的optgroup。
1
United States
Antigua and Barbuda
Anguilla
...
7
Russian Federation
Kazakhstan
20
Egypt
...
美国的价值为0,安提瓜和巴布达的价值为1,安圭拉的价值为2,俄罗斯联邦的价值为0,等等。这不是我想要的。美国,安提瓜和巴布达以及安圭拉的价值应为1.俄罗斯联邦,Kazahkstan的价值应为7,埃及的价值应为20.这样的事情是否可能?
答案 0 :(得分:0)
您需要创建一个包含键值的数组
$thatarray=array(
"1" => "United States"
"1" =>"Antigua and Barbuda",
"1" =>"Anguilla",
"1" =>"American Samoa",
"1" =>"Barbados",
"7" => "Russian Federation",
"7" =>"Kazakhstan",
"20" => "Egypt",
./*other countries */
.
.
.
.
);
$builder->add('callingCode', 'choice', array('choices' => $thatarray));