Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.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 - Fatal编程技术网

PHP如何删除数组中的数组?

PHP如何删除数组中的数组?,php,arrays,Php,Arrays,我有这样一个数组: $_SESSION = Array ( [chose_image] => Array ( [56915e7c48177e251e1c16f1] => Array ( [title] => title1 [author] => author1 [watermark] => watermark1

我有这样一个数组:

$_SESSION = Array ( 
        [chose_image] => Array (
             [56915e7c48177e251e1c16f1] => Array (
                [title] => title1
                [author] => author1 
                [watermark] => watermark1 
                [file_name] => name1.jpg 
                [visible] => 1 
                [_id] => MongoId Object ( [$id] => 56915e7c48177e251e1c16f1 )
             ) 
            [56915dad48177ee21d1c16f0] => Array (
                [title] => title2
                [author] => author2
                [watermark] => watermark2
                [file_name] => name2.jpg
                [visible] => 1
                [_id] => MongoId Object ( [$id] => 56915dad48177ee21d1c16f0 )
            )
        )
    )
我想删除整个数组:

Array (
             [56915e7c48177e251e1c16f1] => Array (
                [title] => title1
                [author] => author1 
                [watermark] => watermark1 
                [file_name] => name1.jpg 
                [visible] => 1 
                [_id] => MongoId Object ( [$id] => 56915e7c48177e251e1c16f1 )

通过使用[$id]。通过$id执行此操作非常重要,因为数组是由用户动态填充的。有可能吗?

您可以尝试以下操作:
unset($\u SESSION['selected\u image'][$id])
$\u会话['selected\u image'][$id]=null

尝试以下方法:

$sample_id = "56915e7c48177e251e1c16f1"; // for example
$_SESSION['chose_image'] = array_filter($_SESSION['chose_image'], function($v) use($sample_id){
    return $v["_id"]->$id != $sample_id; // Though $id is bad name for object property
});

这就是为unset()创建的
unset()
,unset将通过两种方式删除索引。。一个是未设置的,另一个是创建新数组并忽略此数组