【发布时间】:2017-11-24 10:18:50
【问题描述】:
我有一个数组 $items 。它具有某些元素,例如 Array([0]=>1 1=>2 [2]=>3) 。从这个数组中,我可以删除第一个和第二个索引。但我无法使用数组取消设置方法删除第 0 个索引。
有没有办法从数组中删除第 0 个索引?
提前谢谢...
<?php
session_start();
$items = $_SESSION['cart'];
$cartitems = explode(",", $items);
print_r($cartitems);
if(isset($_GET['remove']) & !empty($_GET['remove'])){
$delitem = $_GET['remove'];
unset($cartitems[$delitem]);
$itemids = implode(",", $cartitems);
$_SESSION['cart'] = $itemids;
if($_GET['remove']==0)
{
unset($cartitems[0]);
$itemids = implode(",", $cartitems);
$_SESSION['cart'] = $itemids;
}
//echo "<script>alert('removed Successfully ');window.location= '".('hide.php')."'</script>";
}
?>
我有上面的代码。因为我从$_GET['remove'].获取键(索引)所以我将从数组中取消设置该特定键。但我无法取消设置其他索引。
我无法从阵列中取出电视机。
【问题讨论】: