Home > Article > Backend Development > How to delete multiple array object attribute values in PHP
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"] = ''].
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!