muppet77 Posted July 20, 2015 Share Posted July 20, 2015 how do you unset or clear or empty a variable variable please? i have seen : unset($variable) but can't get this to work on variable variables. The one i am using is called ${"hcorner".$h} Any ideas please? Thank you. Quote Link to comment Share on other sites More sharing options...
scootstah Posted July 20, 2015 Share Posted July 20, 2015 Works for me. unset(${"hcorner".$h}); Quote Link to comment Share on other sites More sharing options...
requinix Posted July 20, 2015 Share Posted July 20, 2015 Don't use variable variables! An array is a perfectly adequate way of dealing with multiple values. Quote Link to comment Share on other sites More sharing options...
muppet77 Posted July 21, 2015 Author Share Posted July 21, 2015 Thanks. Maybe it's another part of code that is faulty as I have tried unset. (What is the advantage of not using variable variables?) Quote Link to comment Share on other sites More sharing options...
muppet77 Posted July 21, 2015 Author Share Posted July 21, 2015 Scootstah, in my example, doesn't unset only unset whatever $h is at that point in the code? If so I need to unset all keys used in the variable. Thank you. Quote Link to comment Share on other sites More sharing options...
muppet77 Posted July 21, 2015 Author Share Posted July 21, 2015 SOLVED - i used a while loop to increase $h and reset every variable variable individually. maybe not the best way but it works. thanks all Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted July 21, 2015 Share Posted July 21, 2015 (What is the advantage of not using variable variables?) variable variable references take three times longer then an equivalent array reference. if you have a set of related data, that's what arrays are for. you can then use php's array functions to operate on the data, generally without any need to explicitly loop over each value and without writing out line after line of code referencing each discrete variable. Quote Link to comment Share on other sites More sharing options...
scootstah Posted July 21, 2015 Share Posted July 21, 2015 variable variable references take three times longer then an equivalent array reference. That, and it's "magic". It's difficult to inspect them or figure out what is going on at first glance. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.