doudanglang5826 2012-05-24 14:02
浏览 46
已采纳

从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...

  • 写回答

1条回答 默认 最新

  • duanhuau567787 2012-05-24 14:23
    关注

    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
    );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?