Home

unset

Unset is a term used in computing to describe the removal of a binding from a namespace. It typically refers to a command or function that deletes a named variable, function, or other symbol so that it is no longer recognized by subsequent code.

In Unix-like shells such as bash, ksh, and zsh, unset is a builtin command used to remove

In PHP, unset() destroys the specified variable, at the current scope, or an element of an array.

Other languages and environments use similar ideas with different names, such as undef, delete, or Remove-Variable.

names
from
the
current
shell
environment.
The
common
syntax
is
unset
name
[name
...].
Options
often
include
-v
to
unset
variables
and
-f
to
unset
function
definitions.
When
applied
to
arrays,
unset
can
delete
the
entire
array
variable
or
individual
elements
(for
example,
unset
arr[1]
removes
the
second
element).
If
a
variable
is
read-only,
an
attempt
to
unset
it
may
fail.
Unsetting
an
environment
variable
means
it
will
not
be
inherited
by
later
child
processes
created
by
the
shell.
Example:
unset($var);
or
unset($array['key']);
When
the
last
reference
to
a
value
is
removed,
memory
may
be
freed
by
the
runtime.
Unsetting
array
elements
or
object
properties
affects
only
the
current
symbol
table
or
structure,
following
normal
scope
and
reference
rules.
The
core
concept
is
to
reduce
namespace
clutter
and
manage
resources
by
removing
bindings
that
are
no
longer
needed.