Home > Backend Development > PHP Problem > How to delete object attributes in php

How to delete object attributes in php

王林
Release: 2023-03-05 20:34:01
Original
4530 people have browsed it

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

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

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!

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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template