我有这样的代码到新元素添加到一个多维数组:PHP:我如何从一个multidemision数组中删除一个元素?
$this->shopcart[] = array(productID => $productID, items => $items);
让我怎么从这个数组中删除一个元素?我想这个代码,但它不工作:
public function RemoveItem($item)
{
foreach($this->shopcart as $key)
{
if($key['productID'] == $item)
{
unset($this->shopcart[$key]);
}
}
}
我得到这个错误:
- 警告:非法偏移类型在取消所有在C:\ Xampplite文件\ htdocs中\ katrinelund \类\ TillRepository.php线
哪条线是50线? – 2009-11-10 17:05:51
第一个代码示例可能会遗漏键周围的某些'-s'。 – erenon 2009-11-10 17:06:40
@ ricebowl:它一定是未设定的。 – erenon 2009-11-10 17:07:37