开发者

assigning letters instead of numbers in a foreach

I have an array like so.

$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."

);

My clients decided to use letters instead of numbers in the database. When I use a foreach to execute what needs to happen they are using numbers and not the corresponding letters.

Here is my 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;'>":"";
    }
    }

The $MSDS_LIST is an array that looks like this.

Array ( [0] => R )


I believe you're confusing the numbers in the $imgPArry variable for those of your master array. The numbers you see being reference on the $imgPArry are because of the explode happening to a single value from your master array. In other words, the foreachis working properly with the letters.

During each iteration of the foreach, an explode is happening to the value, breaking it at the :. This new subarray then has several parts, depending on how many : were in the value. Those are referenced by numbers.

For example,

"Latex Warning: Caution this product contains natural rubber latex, which may cause allergic reactions!"

...becomes...

$imgPArry[0] = "Latex Warning";
$imgPArry[1] = " Caution this product contains natural rubber latex, which may cause allergic reactions!";

Does that answer your question?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜