-1
私はそういう配列を持っています。foreachの数字の代わりに文字を割り当てる
$ARR_MSDS=array(
'K' => "Latex Warning: Caution this product contains natural rubber latex, which may cause allergic reactions!",
'L' => "Additional Shipping Charges: Please note that standard shipping costs do not apply. This item requires an oversized and/or overweight shipping surcharge. Total shipping charges will be calculated upon receipt of order and you will be called with exact total.",
'M' => "Bariatric Rated: Please note that this product has a Bariatric rating." ,
'B' => "HazMat: Non-returnable. This item is classified as a hazardous material by DOT and has the following shipping restrictions: ground shipping only (no air shipments) and only ship to the 48 continuous states. Additional shipping charges may apply.",
'P' => "Refrigerated Item: Shipped on ice only Monday - Wednesday.",
'E' => "Prescription Drug or Device: This item may only be sold to a licensed healthcare facility.",
'A' => "Special Order: This item is a special order and is non-returnable. Please ensure this is the item you want. If you have any questions, please contact us. It may be drop shipped from the manufacturer.",
'X' => "Earth-Friendly: This item is certified Earth-Friendly.",
'V' => "Controlled Drug: Requires a DEA license and may only be shipped to the address on the license.",
10 => "Class II Drug: Non-refundable. This drug requires an original DEA Form 222 to be in our hands prior to shipping your order. Please contact us if you require assistance.",
'T' => "No Return: Cannot be sent back.",
'C' => "Short-Dated Item: This item has a shorter shelf life, usually less than 6 months, and is priced accordingly. This item is non-returnable."
);
私のクライアントは、データベースで数字の代わりに文字を使用することに決めました。私はforeachを使用して何が起こる必要があるかを実行するときに、対応する文字ではなく数字を使用しています。
ここは私のforeachです。
foreach($ARR_MSDS as $k=>$v){
$imgPArry = explode(":",$v);
$imgPath = $imgPArry[0];
$imgTile = "<span ><strong>".$imgPArry[0]."</strong>";
$imgTile1 = $imgPArry[1];
if($imgPArry[2]!='')
{
$tileMain = $imgTile ." :".$imgTile1." ".$imgPArry[2]."</span>";
}else{
$tileMain = $imgTile ." :".$imgTile1."</span>";
}
if(is_array($MSDS_LIST)){
//onmouseover=\"Tip('<strong>Please call customer service at 1(800) 748-5665 to order item</strong>', BALLOON, true, ABOVE, true, OFFSETX, -17)\"
$MSDS_LIST_RESULT.=(in_array($k,$MSDS_LIST))?"<img src='/images/msdx/$imgPath.gif' onmouseout=\"hideDiv()\" onmouseover=\"showDiv('$tileMain')\" style='padding:2px;margin:0px;'>":"";
}
else{
$MSDS_LIST_RESULT=($k==$MSDS_LIST)?"<img src='/images/msdx/$imgPath.gif' title='$v' style='padding:2px;'>":"";
}
}
$ MSDS_LISTは、次のような配列です。
配列([0] => R)
どういうところですか?元の例のように、英数字キーを使用してPHPで連想配列を使用できます。 'foreach($ ARR_MSDS $ $ => $ v){'のようにforeachすると、$ kが鍵になり、$ vがその値になります。配列上で 'print_r'を実行して、それが期待しているキーがあることを確認してください。 – MightyE
はい、ここに質問はありません:/ – sevenseacat
私はリストに隠れてしまったキーで '10'を見ています...これは問題ですか? –