This article mainly introduces the method of deleting and reassigning multiple array object attributes in PHP, involving related implementation skills of PHP combined with sphinx to operate array elements. Friends in need can refer to the following
The examples of this article are described PHP implements the method of deleting and reassigning the properties of multiple array objects. Share it with everyone for your reference, the details are as follows:
Example: The results searched by sphinx need to remove a certain attribute value:
$cl = new SphinxClient (); $query = $cl->Query ( $keyword, $index );
Method one, delete the attribute directly:
foreach ( $query['matches'] as $k => $val ) { unset($query['matches'][$k]["attrs"]["content"]); unset($query['matches'][$k]["attrs"]["remarks"]); }
Method two, 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 => in the foreach loop ; $val Gets the subscript of a specific element, otherwise it cannot be operated.
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 How to delete multiple array object attributes and reassign them in PHP. For more information, please follow other related articles on the PHP Chinese website!