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

How to delete attributes in php

藏色散人
Release: 2023-03-08 21:38:02
Original
2539 people have browsed it

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

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!

Related labels:
php
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template