Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从数组中删除数据_Php_Arrays_Unset - Fatal编程技术网

Php 从数组中删除数据

Php 从数组中删除数据,php,arrays,unset,Php,Arrays,Unset,我在从数组(会话)中删除数据时遇到这个问题 我的代码是: $cart = $this->session->userdata('cart'); $sess_product_name = $cart['product_name']; $sess_prod_id = $this->input->post('sess_prod_id'); foreach($sess_product_name as $key => $value) : if($key == $ses

我在从数组(会话)中删除数据时遇到这个问题

我的代码是:

$cart = $this->session->userdata('cart');
$sess_product_name = $cart['product_name'];
$sess_prod_id = $this->input->post('sess_prod_id');

foreach($sess_product_name as $key => $value) :
    if($key == $sess_prod_id) :
        unset($sess_product_name[$value]);
        $sess_product_name = array_values($sess_product_name);
    endif;
endforeach;
即使如此,数组也没有任何变化:(请帮助


非常感谢您的帮助!

$value
是与该键关联的值。如果要删除该值,请
取消设置关联的键:

unset($sess_product_name[$key]);