Home  >  Article  >  Backend Development  >  PHP implements deleting multiple array object attributes and reassigning them

PHP implements deleting multiple array object attributes and reassigning them

陈政宽~
陈政宽~Original
2017-06-28 13:44:171370browse

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!

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