开发者

PHP - count my quantity item in session array

How to count the item-qty and current code :-

$q = $_POST['item-qty'];
$i = count($q);
$k = 0;

while ($k < $i) {
  $select = 'SELECT * FROM location';
  $query = $db->rq($select);
  $price = $db->fetch($query);

  if ($_POST['item-qty'][$k] < 3) {

      $get = $price['normal_price'];
      $price = $get * $_POST['item-qty'][$k];

      $_SESSION['order'][$_POST['item-id'][$k]] = array(
      "item-id" => $_POST['item-id'][$k],
      "item-qty" => $_POST['item-qty'][$k],
      "item-name" => $_POST['i开发者_如何学JAVAtem-name'][$k],
      "item-price" => $price,
       );

  } else {

      $get = $price['member_price'];
      $price = $get * $_POST['item-qty'][$k];

      $_SESSION['order'][$_POST['item-id'][$k]] = array(
      "item-id" => $_POST['item-id'][$k],
      "item-qty" => $_POST['item-qty'][$k],
      "item-name" => $_POST['item-name'][$k],
      "item-price" => $price,
      );
  }
}

here the array output

Array
(
[order] => Array
    (
        [1] => Array
            (
                [item-id] => 1
                [item-qty] => 1
                [item-name] => Adidas
                [item-price] => 100
            )

        [2] => Array
            (
                [item-id] => 2
                [item-qty] => 1
                [item-name] => Nike
                [item-price] => 150
            )

    )

)

Question :

  1. How to implement other code if item-qty (in all array) is greater than or equal to 3 will use $price['member_price']

let me know :)


I'm guessing you meant the total item-qty of everything?

$qty_sum = 0
 foreach($_SESSION['order'] as $order){
     $qty_sum += $order['item-qty'];
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜