PHP what is faster to use

Posted by user1631500 on Stack Overflow See other posts from Stack Overflow or by user1631500
Published on 2012-08-28T21:23:47Z Indexed on 2012/08/28 21:38 UTC
Read the original article Hit count: 217

Filed under:
|

What is faster / better to use?

To put html into variables and print them later, or to just html print / echo print the content based on condition?

EXAMPLE 1:(html into variables)

if(!isset($_SESSION['daddy'])) {

$var = "<span class='something'>Go here:<a href='#'>Click</a></span>
        <span class='something'>Go here:<a href='#'>Click</a></span>"

} else {

$one=$_SESSION["one"];
$two=$_SESSION["two"];
$three=$_SESSION["three"];

$var = You are cool enough to view the content;


}

echo $var;

EXAMPLE 2:(print based on condition)

if(!isset($_SESSION['daddy'])) {

$var = 1;

} else {

$one=$_SESSION["one"];
$two=$_SESSION["two"];
$three=$_SESSION["three"];

$var = 0;


}

if ($var==1) {

?>

<span class='something'>Go here:<a href='#'>Click</a></span>
<span class='something'>Go here:<a href='#'>Click</a></span

<?php

} else {
?>

You are cool enough to view the content.

<?php
}
?>

© Stack Overflow or respective owner

Related posts about php

Related posts about micro-optimization