Hello Universe
Hello Universe

Reputation: 3302

How is this if statement working

<?php if ($result->getSellerLocation()) : ?> <?php endif;?>  

Hi

Can someone please explain what is the code above is doing? I know how the normal if else works.. what is the final : at the end

Upvotes: 1

Views: 54

Answers (1)

gillytech
gillytech

Reputation: 3686

It's the alternate syntax for if statements. We usually use it when there is interceding HTML to be output in the final result.

This method is said to increase readability.

For example:

<?php if ($foo == $bar) : ?>
    <p class="conclusion"> $foo does equal $bar </p>
<?php endif; ?>

You can also use else if :.

This works essentially the same as:

<?php if ($foo == $bar) { ?>
    <p class="conclusion"> $foo does equal $bar </p>
<?php } ?>

or:

<?php
    if ($foo == $bar) {
       echo '<p> $foo does equal $bar </p>';
    }
?>

Hope this helps!

Upvotes: 4

Related Questions