graham23s Posted September 4, 2007 Share Posted September 4, 2007 Hi Guys, i thought i was in a pretty good routine when typing my code but now everywhere i see this: {$variable} when i normally do just: $variable can anyone tell me why this needs done? and should i make it a rule of thumb to do it also? thanks guys Graham Quote Link to comment https://forums.phpfreaks.com/topic/67956-solved-curly-braces-round-variables/ Share on other sites More sharing options...
roopurt18 Posted September 4, 2007 Share Posted September 4, 2007 It depends. Inside of double quotes, using curly braces just makes it more clear to the PHP parser which part of the string is the variable and which part is the string: // Assume a variable named $prefix echo "That is $prefixtacular!"; // The PHP parser would look for a variable named $prefixtacular and most likely not find it echo "That is {$prefix}tacular!"; // No confusion in the above statement The second use of curly brackets concerning variables is for declaring or using a variable with a dynamic name. // Assume a variable named $name holding the value "bob" ${$name} = "Hello"; The statement above will create a variable named $bob and assign it a value of "Hello" Quote Link to comment https://forums.phpfreaks.com/topic/67956-solved-curly-braces-round-variables/#findComment-341554 Share on other sites More sharing options...
graham23s Posted September 4, 2007 Author Share Posted September 4, 2007 ah i see, its just good practice to do it in certain parts thanks mate:) Graham Quote Link to comment https://forums.phpfreaks.com/topic/67956-solved-curly-braces-round-variables/#findComment-341565 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.