Home > Article > Backend Development > How to delete object attributes in php
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.
# 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!