Home  >  Article  >  Backend Development  >  How to delete object attributes in php

How to delete object attributes in php

王林
王林Original
2020-09-11 13:32:234379browse

php method to delete the attributes of an object: You can use the unset() function to delete. The unset() function is used to destroy a given variable, such as [unset($address['addAddress']);], which means to delete the [addAddress] attribute of the address object.

How to delete object attributes in php

# The unset() function is used to destroy the given variable.

(Video tutorial recommendation: php video tutorial)

For example:

unset($address['/Api/User/addAddress']);

means that the address object's '/Api/User/addAddress' has been deleted Attributes.

Code sample:

define('CLI_SCRIPT', true);
$user = new stdClass();
$user->id = 1;
$user->name = 'tony';
$user->age = 23;
var_dump($user);
unset($user->name);
var_dump($user);

Related recommendations:php training

The above is the detailed content of How to delete object attributes in php. 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