dennismonsewicz Posted January 6, 2009 Share Posted January 6, 2009 can someone explain what a variable's variable is used for? I have read up on it but it doesn't make sense Quote Link to comment https://forums.phpfreaks.com/topic/139736-solved-variables-variable/ Share on other sites More sharing options...
premiso Posted January 6, 2009 Share Posted January 6, 2009 In what sense? Are you referring to the $$ command? Really this should not be used, but here is an example: <?php $varname = "var1"; $var1 = "bob"; echo $$varname; ?> The above should echo "bob", however this is why we have arrays... <?php $varname = array("var1" => "bob"); echo $varname["var1"]; ?> Same logic. Quote Link to comment https://forums.phpfreaks.com/topic/139736-solved-variables-variable/#findComment-731079 Share on other sites More sharing options...
dennismonsewicz Posted January 6, 2009 Author Share Posted January 6, 2009 ah gotcha... it just doesn't make sense to use.. at least to me.. doesn't seem like there is a need for it. Quote Link to comment https://forums.phpfreaks.com/topic/139736-solved-variables-variable/#findComment-731080 Share on other sites More sharing options...
PFMaBiSmAd Posted January 6, 2009 Share Posted January 6, 2009 Also, variable variables are three times slower than using an array. Quote Link to comment https://forums.phpfreaks.com/topic/139736-solved-variables-variable/#findComment-731088 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.