开发者

Manipulate session multi-array

I wanna to manipulate each variable inside my Array. I dont know how take a value for each array.

    <?php
    session_start();
    /*array  name, howmuch, cost*/
    $_SESSION['ID'][] = array("Soup", 3 , 1.25);
    $_SESSION['ID'][] = array("Puos", 1 , 3.25);

    foreach ($_SESSION['ID'] as $product=>$value){

        foreach ($value as $var)
       {
           /*HERE echo ("UR produc开发者_开发技巧t is ". name );
                  echo (howmuch);
                  echo (costo*0.40 );  */
        }
     echo ("<br>"); }
      session_destroy();   ?>

Grettings all.


// loop with $product as a reference
foreach ($_SESSION['ID'] as &$product) {
   // 60% discount on every price
   $product[2] *= 0.4;
}

or

// use full path to each value to be changed
foreach ($_SESSION['ID'] as $key=>$product) {
   // 60% discount on every price
   $_SESSION['ID'][$key][2] *= 0.4;
}


foreach ($_SESSION['ID'] as $value) {
    // $value will be array("Soup", 3 , 1.25), for example
    echo $value[0];
    echo $value[1];
    echo $value[2];
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜