Home > Article > Backend Development > PHP implements deleting multiple array object attributes and reassigning them
This article mainly introduces the method of PHP to delete multiple arrayobject attributes and reassign them. It involves related implementation skills of PHP combined with sphinx to operate array elements. Friends who need it can Refer to the following
The example of this article describes the method of deleting and reassigning the properties of multiple array objects in PHP. Share it with everyone for your reference, the details are as follows:
Example: sphinxSearch results, you need to remove a certain attribute value:
$cl = new SphinxClient (); $query = $cl->Query ( $keyword, $index );
Method 1, Delete the attribute directly:
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 value:
foreach ( $query['matches'] as $k => $val ) { $query['matches'][$k]["attrs"]["content"] = ''; $query['matches'][$k]["attrs"]["remarks"] = ''; }
Note: The key to operating multiple arrays is to use as $k => $val in the foreach loop to obtain the subscript of the specific element, otherwise the operation cannot be performed.
Another: When using sphinx search in php, please refer to the implementation method of enabling sphinx full-text search in php
The above is the detailed content of PHP implements deleting multiple array object attributes and reassigning them. For more information, please follow other related articles on the PHP Chinese website!