我有這樣的代碼到新元素添加到一個多維數組: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