Guest Cashster09 Posted May 22, 2009 Report Share Posted May 22, 2009 I am going thru some tutorials and came across this and wondered why? I am a beginner with this stuff...thanks in advance on the echo statements they are surrounded by "". HOw come the variables are surrounded by quotes and a period? Why not just "Perform addition: 2 + 4 = $addition"; $addition = 2 + 4; $subtraction = 6 - 2; $multiplication = 5 * 3; $division = 15 / 3; $modulus = 5 % 2; echo "Perform addition: 2 + 4 = ".$addition."<br />"; echo "Perform subtraction: 6 - 2 = ".$subtraction." "; echo "Perform multiplication: 5 * 3 = ".$multiplication." "; echo "Perform division: 15 / 3 = ".$division." "; echo "Perform modulus: 5 % 2 = " . $modulus . ". Modulus is the remainder after the division operation has been performed. In this case it was 5 / 2, which has a remainder of 1."; thanks in advance, Rich Quote Link to comment Share on other sites More sharing options...
jlhaslip Posted May 22, 2009 Report Share Posted May 22, 2009 The period is a concatenation operator. It separates different parts of the string to be echo'd out. echo "This part " . $this_variable . " and another part. "; Notice also that the same output can be done using single quotes: echo 'This part ' . $this_variable . ' and another part. '; Or Double quotes as you suggest: echo "This part $this_variable and another part. "; Test script: $this_variable = "This Variable"; echo "This part " . $this_variable . " and another part. "; echo 'This part ' . $this_variable . ' and another part. '; echo "This part $this_variable and another part. "; ?> The biggest difference is that the single quote stuff does not get 'parsed' and it will be faster on the Server. Not a big deal on a small script, but it can bog down on a larger script. Quote Link to comment Share on other sites More sharing options...
Guest Cashster09 Posted May 22, 2009 Report Share Posted May 22, 2009 (edited) Ok, now i see! I was looking at all the quotes differently....it looked like there were quotes around the variables.... It really is echo "Perform addition: 2 + 4 = " .$addition. " "; So the concatenation can have spaces or not? echo "Perform addition: 2 + 4 = " . $addition . " "; Which is easier to read and decipher than the one below echo "Perform addition: 2 + 4 = ".$addition." "; both these are correct, then? Edited May 22, 2009 by Cashster09 Quote Link to comment Share on other sites More sharing options...
jlhaslip Posted May 22, 2009 Report Share Posted May 22, 2009 Correct. I 'space them out' so they are easier to read. Personal choice. Quote Link to comment Share on other sites More sharing options...
Guest Cashster09 Posted May 22, 2009 Report Share Posted May 22, 2009 Cool!... Now i can sleep at nite knowing that i understand something about php.... 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.
Note: Your post will require moderator approval before it will be visible.