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 Link to comment https://forums.phpfreaks.com/topic/199151-help-me-understand/ 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". Link to comment https://forums.phpfreaks.com/topic/199151-help-me-understand/#findComment-1045251 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. Link to comment https://forums.phpfreaks.com/topic/199151-help-me-understand/#findComment-1045258 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. Link to comment https://forums.phpfreaks.com/topic/199151-help-me-understand/#findComment-1045273 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. Link to comment https://forums.phpfreaks.com/topic/199151-help-me-understand/#findComment-1045279 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. Link to comment https://forums.phpfreaks.com/topic/199151-help-me-understand/#findComment-1045284 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.