monkeytooth Posted April 20, 2010 Share Posted April 20, 2010 Often when I get stuck on a concept I go looking for answers but today I finally noticed a trend, one of which I don't practice often it seems, or one that I go about in different ways I guess you could say sometimes. Anwyay what I notice is some people code and they will have multiple breaks in the code <?php some php code if($random){ ?> some html/or not <?php } else { ?> some more html/or not <?php } ?> then ill see a concept one of which I do more it seems <?php if($random){ //building my vars and having it deside what the output is }else{ //well my logic was off it didnt work right use default values } ?> HTML stuff/or not I guess what I am curious about is why some people code one way or another and what between the two if one is more so than the other the best way to code in PHP Quote Link to comment Share on other sites More sharing options...
havenpets Posted April 20, 2010 Share Posted April 20, 2010 I use both depending on the situations. When retrieving data from my database, and I am inserting them into a table, I simply use the breaks. However, if I am coding something other than that, I continue with an "echo". Quote Link to comment Share on other sites More sharing options...
MatthewJ Posted April 20, 2010 Share Posted April 20, 2010 I tend to open and close php blocks so I can still see the html represented in Dreamweaver instead of just seeing php badges in it's place. Plus lots of concatenation can get tricky to read at times. Quote Link to comment Share on other sites More sharing options...
ignace Posted April 20, 2010 Share Posted April 20, 2010 I mostly use the first example in my views. Quote Link to comment Share on other sites More sharing options...
cweathers Posted April 20, 2010 Share Posted April 20, 2010 I'm not aware of a functionality difference. Seems like it's all about aesthetics, preference, and/or how you were taught. I prefer the second method. Quote Link to comment Share on other sites More sharing options...
monkeytooth Posted April 20, 2010 Author Share Posted April 20, 2010 Ok thats what I wasn't sure about, if it was just preference of some form of optimization or what. But from what im reading and understanding from it, it is like you say a matter of preference and that way you learned or were taught. 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.