Hướng dẫn unset object key php
Asked 2 years, 1 month ago Viewed 95 times I'm trying to unset a key in all objects in an array of objects (basically removing any passwords), doing this:
But it seems it doesn't effect the 'original' data ... how do I do this by reference (or whatever it takes to make this work as 'expected' – by which I mean, the key is removed from all objects in the original array)? asked Aug 26, 2020 at 9:02 0 You can pass the
answered Aug 26, 2020 at 9:05
CidCid 14.5k4 gold badges26 silver badges43 bronze badges 1 Try:
Or
answered Aug 26, 2020 at 9:05
Daniel KemenyDaniel Kemeny 6101 gold badge5 silver badges11 bronze badges My suggestion:
answered Aug 26, 2020 at 12:22
AbsoluteBeginnerAbsoluteBeginner 2,1043 gold badges10 silver badges21 bronze badges 2 (PHP 4, PHP 5, PHP 7, PHP 8) unset — Unset a given variable DescriptionThe behavior of unset() inside of a function can vary depending on what type of variable you are attempting to destroy. If a globalized variable is unset() inside of a function, only the local variable is destroyed. The variable in the calling environment will retain the same value as before unset() was called.
The above example will output: To unset() a global variable inside of a function, then use the $GLOBALS array to do so:
If a variable that is PASSED BY REFERENCE is unset() inside of a function, only the local variable is destroyed. The variable in the calling environment will retain the same value as before unset() was called.
The above example will output: If a static variable is unset() inside of a function, unset() destroys the variable only in the context of the rest of a function. Following calls will restore the previous value of a variable.
The above example will output: Before unset: 1, after unset: 23 Before unset: 2, after unset: 23 Before unset: 3, after unset: 23 Parametersvar The variable to be unset. vars Further variables. Return ValuesNo value is returned. ExamplesExample #1 unset() example
Example #2 Using
The above example will output: Notes
See Also
Hayley Watson ¶ 9 years ago
nox at oreigon dot de ¶ 14 years ago
"Finally that thing is gone\n";?> Kai Kunstmann ¶ 14 years ago
j dot vd dot merwe at enovision dot net ¶ 12 years ago
file_exists ( $file ) == FALSE ) { franckraynal at free dot fr ¶ 17 years ago
andre at twg dot com dot au ¶ 18 years ago
anon at no spam dot no address dot com ¶ 18 years ago
$i = 0; $i < 5; $i++) hessodreamy at gmail dot com ¶ 15 years ago
pfreilly at umd dot umich dot edu ¶ 10 years ago
clark at everettsconsulting dot com ¶ 17 years ago
remove_element (&$array, $key) // pass array by reference phpmanual at kennel17 dot co dot uk ¶ 12 years ago
= array(); tecdoc at ukr dot net ¶ 5 months ago
ray.paseur sometimes uses gmail ¶ 6 months ago
Anonymous ¶ 15 years ago
=array("Hello","World");
lion_cat at mail ru ¶ 13 years ago
dan AT --nospam-- cubeland DOT co DOT uk ¶ 17 years ago
test() { thorry at thorry dot net ¶ 18 years ago
pauljamescampbell at gmail dot com ¶ 14 years ago
Anonymous ¶ 12 years ago
warhog at warhog dot net ¶ 18 years ago
dibakar dot datta at gmail dot com ¶ 16 years ago
edouard dot berge at gmail dot com ¶ 12 years ago
Hayley Watson ¶ 15 years ago
stacionari at gmail dot com ¶ 14 years ago
?>
Andreas ¶ 12 years ago
macnimble at gmail dot com ¶ 13 years ago
" chad 0x40 herballure 0x2e com ¶ 15 years ago
tigercat at aol dot com ¶ 9 years ago
f1() // example of invalid variable reference use muhamad_zakaria at yahoo dot com ¶ 17 years ago
__set($var, $val) { magnesium dot oxide dot play+php at gmail dot com ¶ 8 years ago
bar(){ |