Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.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 在foreach循环中取消多维数组上的值_Php_Arrays_Multidimensional Array_Unset - Fatal编程技术网

Php 在foreach循环中取消多维数组上的值

Php 在foreach循环中取消多维数组上的值,php,arrays,multidimensional-array,unset,Php,Arrays,Multidimensional Array,Unset,我得到了一个多维的对象数组,在某些情况下需要“过滤”。这是我写的函数: foreach($data["index"] as $key => $value){ if(preg_match("/EXPRESSION/",$value->property)){ unset($data["index"][$key]); } } 它不会返回任何错误,但当数组被var_转储时,我认为未设置的值仍然存在 我在另一个话题上发现了这一点: foreach ($this

我得到了一个多维的对象数组,在某些情况下需要“过滤”。这是我写的函数:

foreach($data["index"] as $key => $value){
    if(preg_match("/EXPRESSION/",$value->property)){
        unset($data["index"][$key]);
    }
}
它不会返回任何错误,但当数组被var_转储时,我认为未设置的值仍然存在

我在另一个话题上发现了这一点:

foreach ($this->result['list'] as $key => &$row) {
    if ($this_row_is_boring) {
        unset($this->result['list'][$key]);
    }
}
我认为与我写的唯一不同的是,当我调用$data时,他调用$this->result


有什么想法吗?谢谢

如果正则表达式不匹配,
unset()
将永远不会被调用

您能否插入一条语句来确定
preg\u match()
是否返回true

if(preg_match("/EXPRESSION/",$value->property)){
    unset($data["index"][$key]);
    echo "Match found with \$key: $key\n";
}