I'm confused now and don't understand what is best to use.
$a = null;
or
unset($a);
Tell me more than this or that design is different.
I'm confused now and don't understand what is best to use.
$a = null;
or
unset($a);
Tell me more than this or that design is different.
There is a difference between these two operations.
<?php $fst = 'hello'; $snd = 'world'; $fst = null; unset($snd); echo $fst; // null echo $snd; // Notice: Undefined variable: snd
Assigning a variable to null
, a variable with the value null
left in the symbol table of your script. Removing a variable with the unset()
construct unset()
it from the symbol table.
Correctly delete the unset()
variable. By assigning null
you do not delete the variable, but assign it the value null
- yes isset()
will show false
, but the variable exists. Moreover, you will find a few more subtle points in the case of variable objects and array elements. unset()
will remove both the value and the variable from the symbol table. If you want to delete a variable, delete unset()
.
$a = "10"; $b = &$a; $a = null;
$a = "10"; $b = &$a; $a = null;
- as a result, everything is in null
and if you apply instead of null, unset($a)
, then the $b
variable will exist with a value of 10 ... I just don’t know how to do it ... completely confused, somebody would explain to the shelves, would be grateful - MaximProSource: https://ru.stackoverflow.com/questions/561182/
All Articles
null
says: "Dude, the variable is empty!", Whereasunset
hints: "Smoked stol? There is no such variable." - user207618 8:40 pm