I'm getting all value of this array. I want to get a whom key value in a PHP variable how can i do that.
我得到了这个数组的所有价值。我想在PHP变量中获取一个键值,我该怎么做。
$fields = array('firstNameInput' => 'Name', 'lastNameInput' => 'Surname', 'countryCodeInput' => 'Country', 'phoneNumberInput' => 'Phone', 'emailInput' => 'Email',
'companyNameInput' => 'Company', 'whom' => 'Connect to', 'subjectInput' => 'Subject', 'messageInput' => 'message'
);
foreach ($_POST as $key => $value) {
if (isset($fields[$key])) {
$emailText .= "$fields[$key]: $value\n".$another;
}
}
1 个解决方案
#1
0
I making a code for you, this code is helpful for you.
我为您编写代码,此代码对您有所帮助。
$fields = array(
'firstNameInput' => 'Name',
'lastNameInputd' => 'Surname',
'countryCodeInput' => 'Country',
'phoneNumberInput' => 'Phone',
'emailInput' => 'Email',
'companyNameInput' => 'Company',
'whom' => 'Connect to',
'subjectInput' => 'Subject',
'messageInput' => 'message'
);
$fields2 = array('whom');
$fields2=array_flip($fields2);
$result=array_intersect_key($fields,$fields2);
foreach($result as $value)
{
echo $value.'<br>';
}
I make a new array and pass keys which you want(any key you can pass) in $fields2. now array is Array ( [0] => whom )
array_filp($fields2)
is using for convert value to key . array_intersect_key($fields,$fields2)
given result is
我在$ fields2中创建了一个新数组并传递了你想要的键(你可以传递的任何键)。现在数组是Array([0] => who)array_filp($ fields2)用于将value转换为key。 array_intersect_key($ fields,$ fields2)给出的结果是
Array ( [whom] => Connect to )
finally you have a key result.
最后你有一个关键的结果。
#1
0
I making a code for you, this code is helpful for you.
我为您编写代码,此代码对您有所帮助。
$fields = array(
'firstNameInput' => 'Name',
'lastNameInputd' => 'Surname',
'countryCodeInput' => 'Country',
'phoneNumberInput' => 'Phone',
'emailInput' => 'Email',
'companyNameInput' => 'Company',
'whom' => 'Connect to',
'subjectInput' => 'Subject',
'messageInput' => 'message'
);
$fields2 = array('whom');
$fields2=array_flip($fields2);
$result=array_intersect_key($fields,$fields2);
foreach($result as $value)
{
echo $value.'<br>';
}
I make a new array and pass keys which you want(any key you can pass) in $fields2. now array is Array ( [0] => whom )
array_filp($fields2)
is using for convert value to key . array_intersect_key($fields,$fields2)
given result is
我在$ fields2中创建了一个新数组并传递了你想要的键(你可以传递的任何键)。现在数组是Array([0] => who)array_filp($ fields2)用于将value转换为key。 array_intersect_key($ fields,$ fields2)给出的结果是
Array ( [whom] => Connect to )
finally you have a key result.
最后你有一个关键的结果。