Remove part of associative array

This question already has an answer here:

  • PHP: Delete an element from an array 34 answers

  • Try like this:

    foreach ($this->schs_raw as &$object) {
        if($object['AppService'] == "16295C0C51D8318C2") {
            unset($object);
        }
    }
    

    Eventually:

    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/30108.html

    上一篇: PHP如何从数组中删除

    下一篇: 删除关联数组的一部分