删除关联数组的一部分
这个问题在这里已经有了答案:
像这样尝试:
foreach ($this->schs_raw as &$object) {
if($object['AppService'] == "16295C0C51D8318C2") {
unset($object);
}
}
最后:
foreach ($this->schs_raw as $k => $object) {
if($object['AppService'] == "16295C0C51D8318C2") {
unset($this->schs_raw[$k]);
}
}
array_filter
会帮助(http://php.net/manual/en/function.array-filter.php)
$yourFilteredArray = array_filter(
$this->schs_raw,
function($var) {
return $object['AppService'] != "16295C0C51D8318C2"
}
);
尝试这个:
foreach($this->schs_raw as $key=>$object) {
if($object['AppService'] == "16295C0C51D8318C2") {
unset($this->schs_raw[$key]); // unset the array using appropriate index
break; // to exit loop after removing first item
}
}
链接地址: http://www.djcxy.com/p/30107.html