Home  >  Article  >  Backend Development  >  How to delete multiple array object attribute values ​​in PHP

How to delete multiple array object attribute values ​​in PHP

coldplay.xixi
coldplay.xixiOriginal
2020-08-18 10:08:572040browse

PHP method to delete multiple array object attribute values: 1. Delete the attribute directly, the code is [unset($query['matches'][$k]["attrs"]["content"]) ]; 2. Set the corresponding attribute value to empty, and the code is [["content"] = ''].

How to delete multiple array object attribute values ​​in PHP

PHP implementation method of deleting attribute values ​​of multiple array objects:

Method 1, Directly delete attributes:

foreach ( $query['matches'] as $k => $val ) {
  unset($query['matches'][$k]["attrs"]["content"]);
  unset($query['matches'][$k]["attrs"]["remarks"]);
}

Method 2, set the corresponding attribute value to empty or other required values:

foreach ( $query['matches'] as $k => $val ) {
  $query['matches'][$k]["attrs"]["content"] = '';
  $query['matches'][$k]["attrs"]["remarks"] = '';
}

Note: The key to operating multiple arrays is foreach Use as $k => $val in the loop to obtain the subscript of a specific element, otherwise the operation cannot be performed.

Related learning recommendations: php programming (video)

The above is the detailed content of How to delete multiple array object attribute values ​​in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn