difference between if (condition): else: endif and if (condition) {} else {} in php

4

I have a question about php, I'm pretty new to web programming and I still messed up a bit with php.

my question is, in a php file with the following structure

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>testero</title>
</head>
<body>
<?php
    if(false):
?>
<p>hola</p>
<?php
    else:
?>
<p>adios</p>
<?php
    endif;
?>
</body>
</html>

the html that is shown corresponds to the php code that surrounds it, that is to say it is shown only bye, but nevertheless in the following example

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>testero</title>
</head>
<body>
<?php
    if(false){
?>
<p>hola</p>
<?php
    }else{
?>
<p>adios</p>
<?php
    }
?>
</body>
</html>

both options are shown, why does this happen? someone could explain it to me because I have been looking for stackoverflow (I have not found any questions regarding this topic) and for the official documentation of php and I do not find anything about it ...

Many thanks to all and forgive if it is a repeated question I am still a little lost.

    
asked by Mcruz 08.11.2017 в 17:32
source

1 answer

1

No difference in PHP , they are known as alternative syntax , are normally used when mixing PHP code with HTML, I personally prefer to work with if(false){}else{} by code convention

    
answered by 08.11.2017 в 17:47