-1

我正在处理添加到购物车模块,我最终得到的会话数组是这样的:

    Array
(
    [cart] => Array
        (
            [0] => Array
                (
                    [item] => Array
                        (
                            [item_name] => burger
                            [item_price] => 5
                            [item_qty] => 3
                        )

                )

            [1] => Array
                (
                    [item] => Array
                        (
                            [item_name] => pizza
                            [item_price] => 15
                            [item_qty] => 2
                        )

                )

            [2] => Array
                (
                    [item] => Array
                        (
                            [item_name] => french fries
                            [item_price] => 8
                            [item_qty] => 5
                        )

                )

        )

)

我想从这个数组中删除一个项目,比如名称为“pizza”的项目。我该怎么做??

4

1 回答 1

3
function rem_from_array(&$session_array, $name)
{
  foreach($session_array as $key=>$elem)
    if($elem['item']['item_name']==$name)
    {
      unset($session_array[$key]);

      return;
    }
}

那么你应该只执行以下代码:

rem_from_array($_SESSION['cart'], 'pizza');
于 2013-01-08T16:20:57.080 回答