Monkuar Posted July 14, 2009 Share Posted July 14, 2009 Using this $rowbg = $rowbg == 'ce' ? 'ce bc1' : 'ce'; or using this: $color_one = 'ce bc1'; $color_two = 'ce'; static $i = 0; $color = ($i % 2) ? $color_one : $color_two; $i++; for Alternating colors? ^^ ? Quote Link to comment https://forums.phpfreaks.com/topic/165970-witch-is-faster/ Share on other sites More sharing options...
genericnumber1 Posted July 14, 2009 Share Posted July 14, 2009 Try profiling it and find out! Either way, I would guess the first would be quicker. But as they say, premature optimization is the root of all evil! Choose whatever is the easiest to read, I have a huge feeling that there will be bigger bottlenecks in your code than either of these. Quote Link to comment https://forums.phpfreaks.com/topic/165970-witch-is-faster/#findComment-875355 Share on other sites More sharing options...
rhodesa Posted July 14, 2009 Share Posted July 14, 2009 Quicker? You won't see a difference until you put this in a loop that is processing millions of entries. And even then, compared to the other parts of your code, the time it takes to process this is negligible. But, I would go with the first because it uses 1 variable vs 4, and is cleaner code. But then again, I would probably be using Smarty for my templates, which has an alternate method in it, so I wouldn't have this code at all Quote Link to comment https://forums.phpfreaks.com/topic/165970-witch-is-faster/#findComment-875361 Share on other sites More sharing options...
Monkuar Posted July 14, 2009 Author Share Posted July 14, 2009 Quicker? You won't see a difference until you put this in a loop that is processing millions of entries. And even then, compared to the other parts of your code, the time it takes to process this is negligible. But, I would go with the first because it uses 1 variable vs 4, and is cleaner code. But then again, I would probably be using Smarty for my templates, which has an alternate method in it, so I wouldn't have this code at all Smarty? Im not trying to be mean ahah sorry Quote Link to comment https://forums.phpfreaks.com/topic/165970-witch-is-faster/#findComment-875362 Share on other sites More sharing options...
genericnumber1 Posted July 14, 2009 Share Posted July 14, 2009 Smarty? Im not trying to be mean ahah sorry http://www.smarty.net/ I'm not a big fan, but to each their own (I prefer a different template engine). Smarty's powerful once you learn the syntax. Quote Link to comment https://forums.phpfreaks.com/topic/165970-witch-is-faster/#findComment-875367 Share on other sites More sharing options...
rhodesa Posted July 14, 2009 Share Posted July 14, 2009 For small projects, don't bother with it. But for any bigger site, I find it very handy. Also, I tend to develop the PHP and someone else does the HTML/CSS...so it REALLY helps with the separation of responsibilities. Quote Link to comment https://forums.phpfreaks.com/topic/165970-witch-is-faster/#findComment-875368 Share on other sites More sharing options...
Monkuar Posted July 14, 2009 Author Share Posted July 14, 2009 Smarty? Im not trying to be mean ahah sorry http://www.smarty.net/ I'm not a big fan, but to each their own (I prefer a different template engine). Smarty's powerful once you learn the syntax. I'd rather stick with just php, lol Quote Link to comment https://forums.phpfreaks.com/topic/165970-witch-is-faster/#findComment-875369 Share on other sites More sharing options...
genericnumber1 Posted July 14, 2009 Share Posted July 14, 2009 Actually template engines are quite powerful and useful for separation of logic and presentation (as rhod said) in large projects. I tend to stick with the one baked into zend framework, but pretty much any template engines make a managing a large website much easier. Quote Link to comment https://forums.phpfreaks.com/topic/165970-witch-is-faster/#findComment-875371 Share on other sites More sharing options...
.josh Posted July 14, 2009 Share Posted July 14, 2009 $colors = array('ce bc1','ce'); $colors[$i++ % 2]; example: $colors = array('ce bc1','ce'); while ($list = mysql_fetch_array($result)) { echo $colors[$i++ % 2]; } Quote Link to comment https://forums.phpfreaks.com/topic/165970-witch-is-faster/#findComment-875374 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.