我有一个函数,它从数组中删除元素:
function remove_from_cart($prod_name,$price,$params,$count)
{
$cart = array(
"0" => array (
'name' => 'Bolognese - Small (26cm)',
'params' => '',
'price' => '12'),
"1" => array (
'name' => 'Bolognese - Small (26cm)',
'params' => '',
'price' => '12')
);
$prod_arr = array(
"name"=> $prod_name,
"params"=> $params,
"price" => $price);
$count = count( array_keys( $cart, $prod_arr ));
while(($key = array_search($prod_arr, $cart)) !== false) {unset($cart[$key]);}
return array('cart' => $cart, 'count' => $count);
}
$rem = remove_from_cart('Bolognese - Small (26cm)', '12', $params, 1);
//here is i want to remove just 1 of 2 elements
如何修改此函数以设置我想从数组中删除的元素数量?
谢谢!
函数式编程