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";
}