How to delete multiple array object attributes and reassign them in PHP

怪我咯
Release: 2023-03-10 13:58:01
Original
1371 people have browsed it

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 );
Copy after login

Method one, delete the attribute directly:

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

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"] = '';
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!