Mutley Posted November 10, 2008 Share Posted November 10, 2008 I have a script with lots of this in: $report.="Driver: $username<BR>"; $report.="Racing Style $racingstyle<BR>"; $report.="Car: $row[name] ($row[manufacture])<BR>"; $report.="Max Speed $maxspeed<BR>"; $report.="Acceleration (0-100) $accel<BR>"; $report.="Handling (0-10) $handling<BR>"; $report.="<BR><BR>"; In several functions. I've seen towards the bottom of the script there is a global $report; All I want to know is how can I echo all this data, has 'global' got anything to do with this? And why isn't the variable being over written every time it is done again, e.g. why isn't the above not just "<BR><BR>"? Is it todo with the fullstop at the end of the variable? Thanks, Nick. Quote Link to comment https://forums.phpfreaks.com/topic/132214-solved-global-function-echoing-lots-of-variables/ Share on other sites More sharing options...
Mark Baker Posted November 10, 2008 Share Posted November 10, 2008 It's actually a full stop before the = sign, and it's a shortcut operator for string concatenation "global" allows a variable defined in global scope to be accessed from within the local scope of a function Quote Link to comment https://forums.phpfreaks.com/topic/132214-solved-global-function-echoing-lots-of-variables/#findComment-687237 Share on other sites More sharing options...
flyhoney Posted November 10, 2008 Share Posted November 10, 2008 In PHP, to concatenate strings, you use the '.' operator. '.=' is a shortcut operator that stands for this: <?php $string = $string . ' lolz'; // is the same as $string .= 'lolz'; ?> If a variable is declared as global, that means every part of the script has access to it. If you want to view the $report variable, just place echo $report; somewhere near the bottom of the script. Quote Link to comment https://forums.phpfreaks.com/topic/132214-solved-global-function-echoing-lots-of-variables/#findComment-687239 Share on other sites More sharing options...
wildteen88 Posted November 10, 2008 Share Posted November 10, 2008 Beaten to it .= is the concatenation assignment operator Examples // assignment operator $var1 = 'one'; $var1 = 'two'; echo $var1 // ouputs: two // concatenation assignment operator $var1 .= 'one'; $var1 .= 'two'; echo $var1 // ouputs: onetwo Quote Link to comment https://forums.phpfreaks.com/topic/132214-solved-global-function-echoing-lots-of-variables/#findComment-687240 Share on other sites More sharing options...
Mutley Posted November 10, 2008 Author Share Posted November 10, 2008 Thanks a lot! I can see this coming in useful. However I can't echo the data, I'm trying to insert it into a database field (text) so I can read the results, it just comes out blank. I have the query at the bottom of the file after the functions. Quote Link to comment https://forums.phpfreaks.com/topic/132214-solved-global-function-echoing-lots-of-variables/#findComment-687244 Share on other sites More sharing options...
DarkWater Posted November 10, 2008 Share Posted November 10, 2008 We'd need to see the whole file. Quote Link to comment https://forums.phpfreaks.com/topic/132214-solved-global-function-echoing-lots-of-variables/#findComment-687246 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.