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

报告相同问题?

悬赏问题

  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源