name);" statement."/> name);" statement.">

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

How to delete attributes in php

藏色散人
藏色散人Original
2021-03-22 10:52:562523browse

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.

How to delete attributes in php

The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer

Deleting objects in php A certain attribute

<?php
define(&#39;CLI_SCRIPT&#39;, true);
$user = new stdClass();
$user->id = 1;
$user->name = &#39;tony&#39;;
$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!

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