Forum Moderators: coopster

Message Too Old, No Replies

PHP Basics ...

... is it best to ...

         

le_gber

3:16 pm on Apr 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



when you have plenty of if statements is it best to do

<?php
if(var=result){
print theresults
}
else{
print alternateresults
}
print <br />
print some text

if(var=result2){
print theresults2
}
print <br />
print some text
?>

or

<?php if(var=result){?>
theresults
<?php } else {?>
alternateresults
<? }?>
<br />
some text
<?php if(var=result2){?>
theresults2
<? }?>
<br />
some text

In other word, will the page load faster or the server load be smaller, in ex 1 because it will parse the php all in one go. I think that's the way to write ASP to ease the load on the asp engine.

Thanks

Leo

dcrombie

10:34 am on Apr 21, 2005 (gmt 0)



There was a good thread here a couple of months ago on PHP benchmarking. It was quite comprehensive and considered a range of methods. I'm sure someone can provide a link...

For your specific question, I think the first option was significantly faster.

;)

jatar_k

12:26 am on Apr 22, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Benchmarking PHP text output [webmasterworld.com]

we try to get the best threads in the library [webmasterworld.com] ;)

le_gber

11:41 am on Apr 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



cheers I will have a look

Leo