创建数组,它们具有不同标签的相同值

时间:2015-01-16 08:18:39

标签: php arrays

我在drupal中创建了一个form来找到一个area.in我们对于differet键有相同的值。当我们写下面的数组时,他们将只采用相同值的最后一个键,就像家庭法一样,它只采取限制令,所以我们如何能创建数组,它们将为不同的标签采用相同的值。

function form_test_form($form,&$form_state) 
{
$area_one=array(
'Bankruptcy' =>'Bankruptcy',
'Criminal Defense' =>'Criminal Defense',
'Criminal Defense' =>'Driving Under Influence (of Drugs and or Alcohol)',
'Expungement' =>'Expungement',
'Family Law' =>'Family Law',
'Family Law' =>'Alimony',
'Family Law'=>'Child Custody',
'Family Law' =>'Child Visitation',
'Family Law' =>'Divorce',
'Family Law'=>'Restraining Orders',
'Employment' =>'Employment',
'Immigration'=>'Immigration',
'Immigration'=>'Deportation Defense',
'Personal Injury' =>'Personal Injury',
'Real Estate' =>'Real Estate',
'Taxation' =>'Taxation',
'Workers’ Compensation Applicant'=>'Workers’ Compensation',
'Wills, Trusts & Probate' =>'Wills, Trusts & Probate',
 ); 

$a=array_search('Family Law', array_reverse($area_one));
$form['Lawyername'] = array(
'#title' => t('Select Practice Areas'),
'#type' => 'select',
'#options' => $a,
'#required' => TRUE,
);

$form['Location'] = array(
'#title' => t('California County'),
'#type' => 'textfield',
'#autocomplete_path' => 'form_test-autocomplete-engine',
'#required' => TRUE,
);

 $form['submit'] = array(
 '#value' => 'Submit',
 '#type' => 'submit',
 );
 return $form;
 }

1 个答案:

答案 0 :(得分:1)

您可以array_reverse()数组,然后使用array_search()检索密钥,例如:

echo array_search('Family Law', array_reverse($area_one)); // 'Restraining Orders'

Demo