Hướng dẫn php unset object property
If I have an Sure there's no problem to assign a new property,
But then I want to remove it, so So,
is kind of it. But is there a more 'elegant' way?
YakovL 6,91012 gold badges57 silver badges88 bronze badges
asked Aug 30, 2010 at 13:25
2
This works for array elements, variables, and object attributes. Example:
answered Aug 30, 2010 at 13:26
Yanick RochonYanick Rochon 48.7k24 gold badges122 silver badges195 bronze badges 6 This also works specially if you are looping over an object.
UpdateNewer versions of PHP throw fatal error
Grzegorz 5,3241 gold badge27 silver badges49 bronze badges
answered Sep 9, 2014 at 15:07
Sajjad AshrafSajjad Ashraf 3,6241 gold badge33 silver badges34 bronze badges 2
This also works if you are looping over an object.
No need to use brackets. answered Feb 28, 2019 at 15:49
dandybohdandyboh 1171 silver badge2 bronze badges 1 This code is working fine for me in a loop
answered Jul 29, 2020 at 14:48
Ashiq DeyAshiq Dey 2572 silver badges13 bronze badges 1 Set an element to null just set the value of the element to null the element still exists unset an element means remove the element it works for array, stdClass objects user defined classes and also for any variable
answered Jul 25, 2021 at 18:05
TexWillerTexWiller 3082 silver badges9 bronze badges |