从php中的数组中提取特定变量[关闭]

从php中的数组中提取特定变量[关闭]

问题描述:

This is for an online form for product returns. The user selects from a menu, Refund, Replacement, 90DaysExpired, etc... (choices shown below). Each of those choices, has a corresponding message(inside a variable, also shown below). I want the value of the variable($tbrefund, $tbreplace, etc), based on the choice of the user, to be passed to the variable '$message'.

This is what I have so far, and I get the following error:

Notice: Undefined variable: message

$Rarray = array(
"Refund" => "$tbrefund",
"Replacement" => "$tbreplace",
"90DaysExpired" => "$expiredwarranty",
"ContactTech" => "$contacttech",
"RefundExpiredReplace" => "$outsiderefund",
"NoExRefund" => "$noexchange",
"ManuWarranty" => "$manuwarranty",
);

if (isset($Rarray[$Request]))
   $message =  $Rarray[$Request];

Any help is greatly appreciated.

edit: this is the line producing the error, I already know it's not relevent...

$send_contact=mail($to,$subject,$message,$header);

Why would you downvote someone asking for help? It will only make new people reluctant to ask anything...

这是产品退货的在线表格。 用户从菜单中选择Refund,Replacement,90DaysExpired等...(选项如下所示)。 这些选择中的每一个都有相应的消息(在变量内部,也在下面显示)。 我想根据用户的选择将变量($ tbrefund,$ tbreplace等)的值传递给变量'$ message'。 p>

这是什么 我到目前为止,我得到以下错误: p>

注意:未定义的变量:消息 strong> p>

   $ Rarray = array(
“Refund”=>“$ tbrefund”,
“替换”=>“$ tbreplace”,
“90DaysExpired”=>“$ expiredwarranty”,
“ContactTech”=  >“$ contacttech”,
“RefundExpiredReplace”=>“$ outsiderefund”,
“NoExRefund”=>“$ noexchange”,
“ManuWarranty”=>“$ manuwarranty”,
);  
 
if(isset($ Rarray [$ Request]))
 $ message = $ Rarray [$ Request]; 
  code>  pre> 
 
 

非常感谢任何帮助。 p>

编辑: 这是产生错误的行,我已经知道它不是相关的...... p>

  $ send_contact = mail(  $ to,$ subject,$ message,$ header); 
  code>  pre> 
 
 

为什么你要求某人寻求帮助呢? 它只会让新人不愿意提出任何问题...... p> div>

The error is because $Request is not set correctly.

if (isset($Rarray[$Request]))
{
   $message = $Rarray[$Request];
}
else
{
   $message = "Invalid";
}

So your actual question is "why is $Request not working"?

The answer is it depends on where $Request is coming from, so you need to show us some examples of $Request echoed (or var_dump() ) - but I would hazard a guess that you are sending the $Request lowercase (if it is via a URL or something) - but your array is capitalised.

Edit: and I hope you are not expecting your messages to be something other than "$tbreplace" or something.

I guessing you meant to do something like this?

$Rarray = array(
"Refund" => $tbrefund,
"Replacement" => $tbreplace,
"90DaysExpired" => $expiredwarranty,
"ContactTech" => $contacttech,
"RefundExpiredReplace" => $outsiderefund,
"NoExRefund" => $noexchange,
"ManuWarranty" => $manuwarranty
);