name);var_dump($user);" method."/> name);var_dump($user);" method.">
Home > Article > Backend Development > How to delete elements in an object in php
php method to delete elements in an object: first create a PHP sample file; then delete it through the "var_dump($user);unset($user->name);var_dump($user);" method Just a property of the object.
The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer
How to delete elements in an object with php? How to delete an attribute of an object in php?
unset
<?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);
Related introduction:
unset - Release the given variable
Description
unset(mixed $var, mixed $... = ?): void
unset() Destroy the specified variable 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().
<?php function destroy_foo() { global $foo; unset($foo); } $foo = 'bar'; destroy_foo(); echo $foo; ?>
The above routine will output:
bar
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to delete elements in an object in php. For more information, please follow other related articles on the PHP Chinese website!