name);" statement."/> name);" statement.">
Home >Backend Development >PHP Problem >How to delete attributes in php
How to delete attributes in php: First create a PHP sample file; then delete the attributes of the object through the "unset($user->name);" statement.
The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer
Deleting objects in php A certain attribute
<?php 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);
unset() destroys the specified variable.
The behavior of unset() in a function will vary depending on the type of variable you want to destroy.
If you unset() a global variable in a function, only the local variable will be destroyed, and the variables in the calling environment will maintain the same value before calling unset().
[Recommended learning: PHP video tutorial]
The above is the detailed content of How to delete attributes in php. For more information, please follow other related articles on the PHP Chinese website!